虚拟主机功能: 一个nginx下运行多个网址(站点域名)

  方式一:nginx.conf中的http{}中的每一个server{}就是一个站点(相同端口):        

          #虚拟主机1 

          server { 

            listen 80; 

            server_name www.nginx1.com; 

            location / { 

              #deny 192.168.160.0/24; 

              root /opt/nginxtest/html; 

              index index.html index.htm;

             } 

             location /pic {

               alias /opt/nginxtest/pic; 

            }  

            location /status{ 

              stub_status on; 

            }  

            error_page 404 /404.html; 

          } 

          #虚拟主机2 

          server { 

            listen 80; 

            server_name www.nginx2.com; 

            location / { 

              root /opt/nginxtest/html2; 

              index index.html;

             }

           }

      (同一默认端口:需要在客户端设hi在hosts文件的dnsj解析)----C:\Windows\System32\drivers\etc\hosts

         -----------192.168.160.132 www.nginx1.com

         -----------192.168.160.132 www.nginx2.com

        访问时直接输入域名,默认80

  方式二:nginx.conf中的http{}中的每一个server{}就是一个站点(不同端口指定访问)        

          #虚拟主机1

          server {

            listen 80;

            server_name www.nginx1.com;

            location / {

              #deny 192.168.160.0/24;

              root /opt/nginxtest/html;

              index index.html index.htm;

            } 

            location /pic {

              alias /opt/nginxtest/pic;

            } 

            location /status{

              stub_status on;

            } 

            error_page 404 /404.html;

          } 

          #虚拟主机2

          server {

            listen 81;

            server_name www.nginx1.com;

            location / {

              root /opt/nginxtest/html2;

              index index.html;

            }

          }

     (不同端口:需要在客户端设hi在hosts文件的dnsj解析)

         ----------192.168.160.132 www.nginx1.com:80

          ----------192.168.160.132 www.nginx1.com:81

      访问时输入域名并指定端口

相关文章:

  • 2021-07-27
  • 2021-05-28
  • 2022-02-15
猜你喜欢
  • 2021-09-06
  • 2021-06-22
  • 2021-05-11
  • 2021-09-09
  • 2021-10-07
  • 2021-10-23
  • 2021-07-29
相关资源
相似解决方案