您的位置:首页 > 运维架构 > Nginx

【Nginx】配置基于域名的虚拟主机

2010-10-31 15:57 806 查看
Author:  Matt Song
Date:      2010-04-25

编辑配置文件
vi /opt/nginx/conf/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;
        }
    }
}
创建 index.html
vi /opt/web/www.site1.com/htdocs/index.html
加入:<head><h1>This is SITE 1!!</head></h1>
vi /opt/web/www.site2.com/htdocs/index.html
加入:<head><h1>This is SITE 2!!</head></h1>
vi /opt/web/www.site3.com/htdocs/index.html
加入:<head><h1>This is SITE 3!!</head></h1>
启动Nginx
/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
加HOST测试
192.168.1.100 www.site1.com
192.168.1.100 www.site2.com
192.168.1.100 www.site3.com









 
DONE : )
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  职场 域名 虚拟主机