nginx:vhost

nginx configure multiple vhosts
1. Enter the configuration installation directory cd /usr/local/etc/nginx/conf/
2. There is no vhost folder mkdir vhsot file
3. Add multiple conf files such as: test.com.conf test1.com. conf
4.test.com.conf
  server {
    listen 80;       
    server_name test.com;       
    index index.html index.htm index.php;       
    root /Users/suncg/www/test.com;        
    log_format test.com '$remote_addr - $ remote_user [$time_local] $request' '$status $body_bytes_sent $http_referer' '$http_user_agent $http_x_forwarded_for';       
    access_log /var/log/test.com.log test.com;
}

test1.com.conf
server {
    listen 80;       
    server_name test1.com;       
    index index.html index.htm index.php;       
    root /Users/suncg/www/test1.com;        
    log_format test1.com '$remote_addr - $remote_user [$time_local] $request' '$status $body_bytes_sent $http_referer' '$http_user_agent $http_x_forwarded_for';       
    access_log /var/log/test1.com.log test1.com;
}
5. In /Users/suncg/www/ mkdir test.com and mkdir test1.com and in response folder Create index.html under the content of 1111 and 2222
6. Add include vhost/*.conf in the http{} section of /usr/local/conf/nginx.conf;
such as:
http
{
      #include conf/mime.types;
      include mime. types;
      default_type  application/octet-stream;
      include       vhost/*.conf;

      keepalive_timeout 120;

      tcp_nodelay on;

      upstream  www.samson.com  {
              server   127.0.0.1:8080;
              # server   192.168.1.3:80;
              # server   192.168.1.4:80;
              # server   192.168.1.5:80;
      }

      server
      {
              listen  80;
              server_name  www.samson.com;

              location / {
                       proxy_pass        http://www.samson.com;
                       proxy_set_header   Host             $host;
                       proxy_set_header   X-Real-IP        $remote_addr;
                       proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
              }

              log_format  www_samson_com  '$remote_addr - $remote_user [$time_local] $request '
                                '"$status" $body_bytes_sent "$http_referer" '
                                '"$http_user_agent" "$http_x_forwarded_for"';
              access_log  logs/www.log  www_samson_com;
      }

}

配置host
127.0.0.1  test.com
127.0.0.1  test1.com
访问test.com 显示1111 访问test1.com显示2222

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326270712&siteId=291194637
Recommended