Nginx基于端口的虚机主机配置

  • Post author:
  • Post category:Nginx
  • Page Views 396 阅读

1.基于端口的虚拟主机配置,在基于域名的虚机主机配置之上,修改server区块中的listen端口即可。

    server {
listen 80;
server_name www.test.com;
location / {
root html/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 800;
server_name www.test.com;
location / {
root html/www1;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
[root@CentOS7 conf]# mkdir ../html/www1
[root@CentOS7 conf]# echo "www.test.com:800" > ../html/www1/index.html
[root@CentOS7 conf]# ../sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.16.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.16.1/conf/nginx.conf test is successful
[root@CentOS7 conf]# ../sbin/nginx -s reload
[root@CentOS7 conf]# curl www.test.com
www.test.com
[root@CentOS7 conf]# curl www.test.com:800 #添加端口号访问即可
www.test.com:800


「 文章如果对你有帮助,请点个赞哦^^ 」 

0