Ubuntu under Installation configuration apache2 (with virtual host configuration) 2

Source: Internet
Author: User
Tags hosting web hosting fully qualified domain name

Apache Configuration file httpd.conf description

  1. DocumentRoot "/var/www/html"---Apache default server home directory path
  2. DirectoryIndex index.html index.htm index.php index.html.var---Default document, separated by spaces between multiple files
  3. Listen 192.168.1.1:80 Setting the listening IP is 192.168.1.1 address and port is 80
  4. Listen 192.168.1.2:8080 Setting the listening IP is 192.168.1.2 address and port is 8080
  5. ServerRoot "/ETC/HTTPD" sets the path relative to the root directory, usually where the configuration and log files are stored. The default is:/ETC/HTTPD typically includes conf and logs subdirectories
  6. Errorlog Logs/error_log Setting Error log Note: If the log file storage path does not start with "/", it means that the file is relative to the ServerRoot directory
  7. Customlog Logs/access_log Combined Access log (combined indicates the format used by the log and common format)
  8. ServerAdmin [email protected] Set up the network administrator's email-when the client server error occurs, the server will usually return to the client Error prompt page, in order to facilitate the resolution of the error, this page usually has an administrator's email address, you can use the Se Rveradmin statement to set the administrator's email address
  9. ServerName www.iigoogle.com:80 Set the server host name (if there is a domain name can be filled in the domain name, no domain name can be filled in the server IP address)
  10. Adddefaultcharset GB2312 Sets the default character set and defines the default character set that the server returns to the client (since Western Europe UTF-8 is the Apache default character set, so garbled when accessing a Chinese-language Web page, if you change the character set to GB2312 and then restart the AP Ache service)
  11. Alias/down "/software/download" creates a virtual directory (creates a virtual directory named down, which corresponds to a physical path of:/software/download)
  12. Alias/ftp "/var/ftp" to create the virtual directory (create a virtual directory named FTP, which corresponds to the physical path is:/var/ftp)
  13. <directory "/var/www/html" > Set directory Permissions (<directory "directory path" > This write statement to set directory permissions </Directory>)
  14. Options FollowSymLinks page:116
  15. AllowOverride None
  16. </Directory>


Domain-based virtual host

    1. Namevirtualhost 220.123.55.99---First specify which IP address is responsible for responding to requests to the virtual host with the Namevirtualhost directive
    2. <virtualhost www.iigoogle.com>
    3. ServerName www.iigoogle.com:80
    4. ServerAdmin [email protected]
    5. Documentroot/www/docs/iigoogle
    6. DirectoryIndex index.jsp
    7. Errorlog Logs/www/iigoogle/error_log
    8. Customlog Logs/www/iigoogle/access_log Common
    9. </VirtualHost>


Another way of writing

    1. Namevirtualhost 220.123.55.99:80
    2. <virtualhost www.iigoogle.com:80>
    3. ServerName www.iigoogle.com
    4. ServerAdmin [email protected]
    5. Documentroot/www/docs/iigoogle.com
    6. Errorlog Logs/www/iigoogle/error_log
    7. Customlog Logs/www/iigoogle/access_log Common
    8. </VirtualHost>

What is virtual Hosting (web hosting)?
Simply put, the same server can handle more than one domain name at a time. Assuming that both www.example1.net and www.example2.net have two domain names pointing to the same server, and the Web server supports virtual Hosting, Then www.example1.net and www.example2.net can access different web spaces on the same server (the site file directory).

Configuration format

In Apache2, valid site information is stored in the/etc/apache2/sites-available/user name (file). We can add the format of the following information to increase a valid virtual space, copy most of the contents of the default is OK, remember to change documentroot as the default directory, set the path in directory, note that the port number should not be duplicated with other virtual hosts:

  1. <virtualhost * Custom Ports >
  2. # Add your website name after servername
  3. ServerName Www.jianzhan.love
  4. # If you want multiple site names to get the same site, you can add additional site aliases after Serveralias.
  5. # aliases are separated by a space.
  6. Serveralias ftp.linyupark.com mail.linyupark.com
  7. # after the serveradmin with the webmaster's e-mail address, convenient for others to have a problem is to contact the webmaster.
  8. ServerAdmin [email protected]
  9. # after DocumentRoot, add the directory path (user's personal directory) to store the contents of the website.
  10. Documentroot/home/linyupark/public_html
  11. <Directory/home/linyupark/public_html>
  12. Options Indexes followsymlinks MultiViews
  13. AllowOverride None
  14. Order Allow,deny
  15. Allow from all
  16. </Directory>
  17. scriptalias/cgi-bin//usr/lib/cgi-bin/
  18. <directory "/usr/lib/cgi-bin" >
  19. AllowOverride None
  20. Options execcgi-multiviews +symlinksifownermatch
  21. Allow from all
  22. </Directory>
  23. Errorlog/home/linyupark/public_html/error.log
  24. # Possible values Include:debug, info, notice, warn, error, crit,
  25. # Alert, Emerg.
  26. LogLevel warn
  27. Customlog/home/linyupark/public_html/access.log combined
  28. Serversignature on
  29. </VirtualHost>

If your server has more than one IP, and the different IP has the same virtual user, can be modified to:

    1. <virtualhost IP Address [: Port]>
    2. ...
    3. </VirtualHost>


Enable configuration

The previously configured content is only "effective" virtual host, the actual effect of the words must be placed under the/etc/apache2/sites-enabled folder. We can use the LN command to create a pair of associated files:

sudo ln-s/etc/apache2/sites-available/linyupark/etc/apache2/sites-enabled/linyupark


Check syntax, restart Web service

As a precaution, we check the syntax before restarting the service:

sudo apache2ctl configtest

If there are no errors, then restart Apache.

Sudo/etc/init.d/apache2-k restart

Or

sudo service apache2 restart


View Effects

The main setup work has been completed, it is simple ^_^. How do you see the effect?

Also simple, as long as the host (I use XP) in the table of the host to change the line. The address is:

Windows/system32/drivers/etc

Open and add a sentence:

192.168.1.22 Www.jianzhan.love

The effect is that the browser input www.jianzhan.love will go directly to the IP 192.168.1.22 server to receive the request, see if there is a compatible virtual host domain name, some words to the corresponding directory of the Web file to the requesting user
Errors that may occur

Could not reliably determine the server ' s fully qualified domain name

Modify/etc/apache2/httpd.conf This file is empty, add

ServerName localhost

Can.

Reprint: http://www.knowsky.com/888386.html

Ubuntu under Installation configuration apache2 (with virtual host configuration) 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.