4.Nginx 虚拟主机配置(2)----server

说明: CentOS7.0所属虚拟机在win10上安装.

http {

//1.基于IP的虚拟主机
server{
        listen 80;
       
server_name 192.168.145.128;
        location / {
                root berg;
                index test_ip.html;
         }

    }

//2.基于域名的虚拟主机

//域名需要在C:\Windows\System32\drivers\etc\hosts,设置,如: 192.168.145.128 berg.com
  server{
    listen 80;
    
server_name berg.com;
    location / {
        root berg;
        index index.html;    
     }
 }

//3.基于端口的虚拟主机,需要确认端口号是否被占用
server{
       
listen 2022;
        server_name berg.com;
        location / {
                root /var/www/html;
                index index.html;
         }

    }

//4.默认虚拟主机
    server {
        listen       80;
       
server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

}

猜你喜欢

转载自blog.csdn.net/snail_Bao/article/details/81460858
今日推荐