首页 > 代码库 > Nginx 配置基于域名的虚拟

Nginx 配置基于域名的虚拟

编辑配置文件

vi /etc/nginx/nginx.conf

user    www www;
worker_processes  2;

error_log  logs/error.log  notice;

events {
    worker_connections  1024;
}

http {
    include      mime.types;
    default_type  application/octet-stream;

    log_format  main  ‘$remote_addr -$remote_user [$time_local] "$request" ‘
                     ‘$status $body_bytes_sent "$http_referer" ‘
                     ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    access_log /data/logs/www-logs/http/access.log  main;
   sendfile        on;
    keepalive_timeout  65;

    client_header_buffer_size 1k;
    large_client_header_buffers 4 4k;

    gzip  on;

#虚拟主机1 

  server {        listen       80;        server_name  www.site1.com;        access_log  /data/logs/www-logs/www.site1.com/host.access.log  main;        location / {            root   /data/web/www.site1.com/htdocs;            index  index.html index.htm;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }    }

 

#虚拟主机2  

 server {        listen       80;        server_name  www.site2.com;        access_log  /data/logs/www-logs/www.site2.com/host.access.log  main;        location / {            root   /data/web/www.site2.com/htdocs;            index  index.html index.htm;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }    }

 

#虚拟主机3   

server {        listen       80;        server_name  www.site3.com;        access_log  /data/logs/www-logs/www.site3.com/host.access.log  main;        location / {            root   /data/web/www.site3.com/htdocs;            index  index.html index.htm;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }    }}

 

Nginx 配置基于域名的虚拟