Apache Basic Configuration
In the Ubuntu Apache configuration file is/etc/apache2/apache2.conf,apache automatically reads the configuration information for this file at startup. Some other configuration files are loaded through include.
# Include Module configuration:
includeoptional mods-enabled/*.load
includeoptional mods-enabled/*.conf
# Include List of ports to listen
on Include ports.conf ...
# include generic snippets of statements
includeoptional conf-enabled/*.conf
# include the virtual host Configura tions:
includeoptional sites-enabled/*.conf
Ports.conf, used to set the port on which Apache listens.
Listen
Listen 8080
Virtual Host Configuration
/etc/apache2/sites-enabled/test.conf
# Set the virtual host
<virtualhost *:80>
# site name
ServerName www.test.com
# If you have more than one site name, It can be added to the Serveralias, plus other site aliases.
# Aliases are separated by spaces.
Serveralias www.test.com test.com
ServerAdmin webmaster@localhost
#网站根目录
documentroot/var/www/html
#网站首页面
directoryindex index.php
#目录权限设置
<Directory/mnt/workspace/web/wordblog/>
Options Indexes followsymlinks
#忽略. htaccess
allowoverride None
#允许所有请求访问资源
Require all granted
</Directory>
... </VirtualHost>
When you view the sites-enabled directory with LS, you find a symbolic link to the sites-available directory file. So the/etc/apache2/sites-available directory is the real configuration file.
The benefits are:
If more than one virtual host is configured on Apache, the configuration files for each virtual host are placed under sites-available, so it is convenient to deactivate and enable the virtual host. When a link to a virtual host configuration file is established under Sites-enabled, it is enabled, and if you want to shut down a virtual host, simply delete the link, and you don't need to change the configuration file.
Enable configuration
sudo ln-s/etc/apache2/sites-available/test.conf/etc/apache2/sites-enabled/test.conf
Restart Apache
Sudo/etc/init.d/apache2 Restart nginx Basic configuration
The Nginx configuration is/etc/nginx/nginx.conf and includes the configuration information for the server using include.
http{...
include/etc/nginx/conf.d/*.conf;
include/etc/nginx/sites-enabled/*;
......
}
Nginx and Apache configuration files have almost the same directory structure, sites-enabled and sites-available directories.
Reverse Proxy
/etc/nginx/sites-enabled/test.conf
#反向代理
upstream backend_http {
#ip_hash;
Server 192.168.1.100:8089;
Server 127.0.0.1:8089;
}
server {
listen default_server;
Listen [::]:80 default_server;
#网站的根目录
root/var/www/html;
#网站默认页面
index index.html index.php;
#网站名称
server_name www.test.com;
Location ~ \.php$ {
#设置主机头和客户端真实地址, so that the server obtains the client real IP
proxy_set_header Host $host;
Proxy_set_header x-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
#禁用缓存
proxy_buffering off;
#反向代理的地址
proxy_pass http://backend_http
}
}
Like Apache, if you need to configure multiple virtual hosts on the Nginx, create a profile under Sites-available. Set up a link to a virtual host configuration file under Sites-enabled, then enable it; If you want to shut down a virtual host, simply delete the corresponding link, you do not need to change the configuration file.
Restart Nginx
Sudo/etc/init.d/nginx restart