Apache has just been installed as a local test environment. apache on ubuntu is different from centos. The service process is not httpd, but apache2, and the configuration method is different.
Apache2 configuration Overview & uarr;
On my server, the apache configuration file is under the/etc/httpd directory httpd. conf and the configuration file conf. d/vhost. conf of the virtual host. The configuration directory of Apache2 is/etc/apache2, and the following apache2.conf is the total configuration file, the following directories are referenced: MoD-available, mod-enabled, sites-available, and sites-enabled. load and. conf file. Its logic is simpler, that is, apache2.conf is used as the total configuration file. Some basic configurations are put here, and the available modules and website configurations are put in the MoD-available and sites-available files. "Available" does not mean "enabled". To enable these "available" modules or configurations, you need to place a soft connection in the corresponding enabled Directory. The following is an example:
$ Sudo vi/etc/apache2/sites-available/www.test.com. conf
In this way, the conf file is created, but it will not be immediately used for configuration. Even if you restart the service, it will not take effect. To take effect, you must first "enable" it and reload the service.
The code is as follows: |
Copy code |
$ Sudo ln-s/etc/apache2/sites-available/www.test.com. conf/etc/apache2/sites-enabled/www.test.com. conf |
Then run reload:
The code is as follows: |
Copy code |
$ Sudo service apache2 reload |
To make the configuration take effect. However, apache2 provides an operation. We do not need to use the ln-s command to implement soft links. The command is as follows:
The code is as follows: |
Copy code |
$ Sudo a2ensite/etc/apache2/sites-available/www.test.com. conf
|
A2ensite is equivalent to the abbreviation of apache2 enable site, which means "enable website". In fact, it is to make a soft link to the conf file under the sites-available directory to the sites-enabled Directory. Use this command and then reload the service to enable the website. Similarly, you can use the a2dissite (apache2 disable site) command to stop this website.
Configure virtual host & uarr;
There is no major difference between this and general virtual host configuration, but there is a Require all granted/denied in apache2. The official update description will be described below.
We have already created an www.test.com. conf file. Now we can use it to explain it. Write the following content:
The code is as follows: |
Copy code |
<VirtualHost *: 80> ServerName www.test.com ServerAdmin webmaster@test.com DocumentRoot/var/www/html/www.test.com <Directory/var/www/html/www.test.com> Options FollowSymLinks AllowOverride None Order deny, allow Deny from all </Directory> ErrorLog $ {APACHE_LOG_DIR}/demo_error.log CustomLog $ {APACHE_LOG_DIR}/demo_access.log combined </VirtualHost> |
The overall structure is similar to other virtual host configurations, but this configuration does not have the Require all we will mention below. This statement is added to Apache2 to replace Deny from all and Allow from all. It can be implemented using the following:
The code is as follows: |
Copy code |
<VirtualHost *: 80> ServerName www.test.com ServerAdmin webmaster@test.com DocumentRoot/var/www/html/www.test.com <Directory/var/www/html/www.test.com> Options FollowSymLinks AllowOverride None Require all granted # granted indicates access is allowed, denied indicates access is not allowed </Directory> ErrorLog $ {APACHE_LOG_DIR}/demo_error.log CustomLog $ {APACHE_LOG_DIR}/demo_access.log combined </VirtualHost> |
But in fact, this is not the key, just a small change, the original configuration can actually continue to be used. Some people say that using this method can solve the following problems, but it is actually not feasible, and the logic is not correct.
403 Forbidden & uarr; is displayed when you create a website in the user directory;
403 The reason for forbidden is basically the permission issue. Some people say that the above Require all granted can be removed, but this is not the case. The problem also has something to do with it, but not the virtual host, but the apache2.conf file. After vi apache. conf, you can see that there are several <Directory> </Directory> permissions under control, where there is a require all statement.
We put the web Directory under our own directory to modify and adjust the website without sudo, but apache2 does not recognize your Directory, because apache2 is for the sake of security, only folders under/var/www and/usr/share are allowed to be accessed. Therefore, you can add a allowed Directory after the last </Directory>. For example:
The code is as follows: |
Copy code |
<Directory/home/user/websites> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> |
In this way, you can access this directory by using sudo service apache2 reload. Of course, there is another possibility that the apache User Group www-data has no permission to access your Directory (when the permission control is tight). You also need to consider chmod your directory permissions:
The code is as follows: |
Copy code |
$ Chmod 711/home/user $ Chmod 755/home/user/websites |
Make the directory readable and executable. Then you can access your website.
& Laquo; WP2PCS 1.4.0 plug-in releases backup website to cloud disk calls Baidu cloud disk resources to website