Nginx-虚拟主机

先准备好两个站点:
html

# tree test1.com/ test2.com/
test1.com/
└── index.html
test2.com/
└── index.html
# cat test1.com/index.html 
test1 test html
# cat test2.com/index.html  
test2 test html


配置Nginx:nginx

# cat nginx.conf
#user  nobody;
worker_processes  1;
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  logs/access.log  main;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    gzip  on;
    server {
        listen       80;
        server_name  test1.com;
        access_log      logs/test1.access.log main;
        location / {
            root   /var/www/test1.com;
            index  index.html index.htm;
        }
    }
  
    server {
        listen       80;
        server_name  test2.com;
        access_log      logs/test2.access.log main;
        location / {
            root   /var/www/test2.com;
            index  index.html index.htm;
        }
    }
}


检测配置文件:浏览器

# /opt/nginx/sbin/nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful

从新加载nginx:bash

# /opt/nginx/sbin/nginx -s reload


修改本机的hosts文件,经过本机浏览器访问测试效果:
app

hosts:tcp

192.168.78.131 test1.com
192.168.78.131 test2.com


浏览器访问test1.com 和test2.com 能够访问到不一样的虚拟网站。ide

wKiom1b6NX_yMLUJAAAvzpNFRTU937.png

wKioL1b6Nh_yeS7TAAAxhcuXH5s504.png


更多内容,请关注博主我的博客网站:http://www.whysha.com测试

相关文章
相关标签/搜索