不正狼 发表于 2018-11-10 13:37:43

nginx基于端口的虚拟主机配置

  基于端口的虚拟主机在生产环境中的应用也不多见,仅偶尔会用到,一搬是为公司内部人员提供访问的,如页面的后台、CMS发布、phpmyadmin等。
  1.配置监听的端口
  # vi nginx_vhosts.conf
  server {
  listen       8060;
  server_namewww.etiantian.org;
  location / {
  root   /data0/www/www;
  indexindex.html index.htm;
  access_log /app/logs/www_access.logmain;
  }
  }
  ###
  server {
  listen    8070;
  server_name bbs.etiantian.org;
  location / {
  root   /data0/www/bbs;
  indexindex.html index.htm;
  access_log /app/logs/bbs_access.logmain;
  }
  }
  ###
  server {
  listen       8080;#此端口引起了后患
  server_nameblog.etiantian.org etiantian.org;
  location / {
  root   /data0/www/blog;
  indexindex.html index.htm;
  access_log/app/logs/blog_access.log main;
  }
  }
  ###配置ngnix状态虚拟主机信息
  server
  {
  listen 80;
  server_name status.etiantian.org;
  location /{
  stub_status on;
  access_log off;
  }
  }
  # ../../sbin/nginx -t
  nginx:the configuration file /application/nginx-1.10.1/conf/nginx.confsyntax is ok
  nginx:configuration file /application/nginx-1.10.1/conf/nginx.conftest is successful

  # ../../sbin/nginx -s>  # netstat -lnt|grep 8 #以上3个端口没有监听到,原因是8080端口冲突引起,tomcat设置的也是8080端口
  tcp      0   0 0.0.0.0:32803               0.0.0.0:*                   LISTEN
  tcp      0   0 0.0.0.0:80                  0.0.0.0:*                   LISTEN
  tcp      0   0 :::32803                  :::*                        LISTEN
  tcp      0   0 ::ffff:127.0.0.1:8005      :::*                        LISTEN
  tcp      0   0 :::8009                  :::*                        LISTEN
  tcp      0   0 :::8080                     :::*                        LISTEN
  # vinginx_vhosts.conf
  server {
  listen       8060;
  server_namewww.etiantian.org;
  location / {
  root   /data0/www/www;
  indexindex.html index.htm;
  access_log /app/logs/www_access.logmain;
  }
  }
  ###
  server {
  listen       8070;
  server_name bbs.etiantian.org;
  location / {
  root   /data0/www/bbs;
  indexindex.html index.htm;
  access_log/app/logs/bbs_access.log main;
  }
  }
  ###
  server {
  listen       8081;
  server_nameblog.etiantian.org etiantian.org;
  location / {
  root   /data0/www/blog;
  indexindex.html index.htm;
  }
  }
  # ../../sbin/nginx -t
  nginx:the configuration file /application/nginx-1.10.1/conf/nginx.confsyntax is ok
  nginx:configuration file /application/nginx-1.10.1/conf/nginx.conftest is successful

  # ../../sbin/nginx -s>  # netstat -lnt|grep 80
  tcp      0   0 0.0.0.0:8060                0.0.0.0:*                   LISTEN
  tcp      0   0 0.0.0.0:32803               0.0.0.0:*                   LISTEN
  tcp      0   0 0.0.0.0:8070                0.0.0.0:*                   LISTEN
  tcp      0   0 0.0.0.0:80                  0.0.0.0:*                   LISTEN
  tcp      0   0 0.0.0.0:8081                0.0.0.0:*                   LISTEN
  tcp      0   0 :::32803                   :::*                        LISTEN
  tcp      0   0 ::ffff:127.0.0.1:8005      :::*                        LISTEN
  tcp      0   0 :::8009                  :::*                        LISTEN
  tcp      0   0 :::8080                     :::*
  访问测试:
  通过浏览器访问如下3个地址:测试结果如下:
  http://www.etiantian.org:8060/
  http://www.etiantian.org:8070/
  http://www.etiantian.org:8081/


页: [1]
查看完整版本: nginx基于端口的虚拟主机配置