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測試

相關文章
相關標籤/搜索