zoukankan      html  css  js  c++  java
  • nginx配置之虚拟主机功能

    虚拟主机功能: 一个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:WindowsSystem32driversetchosts

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

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

  • 相关阅读:
    js中this指向的三种情况
    js 对象克隆方法总结(不改变原对象)
    JS 数组克隆方法总结(不可更改原数组)
    第七章、函数的基础之函数体系01
    第六篇、文件处理之文件修改的两种方式
    第六篇、文件处理之文件的高级应用
    第六篇.文件处理之python2和3字符编码的区别
    第六篇、文件处理之字符编码
    第五篇python进阶之深浅拷贝
    jquery的insertBefore(),insertAfter(),after(),before()
  • 原文地址:https://www.cnblogs.com/open-yang/p/11255868.html
Copyright © 2011-2022 走看看