nginx 简单的配置(nginx.conf)

1  基于域名的虚拟主机配置

    server {
        listen       80;
        server_name  www.zyb.com;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       80;
        server_name  bbs.zyb.com;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }


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

    server {
        listen       8080;                     #修改此此处端口
        server_name  www.zyb.com;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }


3 基于IP地址的虚拟机

添加IP地址

[root@centos-6-11 ~]# ip add add 10.0.0.30/24 dev eth0
[root@centos-6-11 ~]# ip add add 10.0.0.31/24 dev eth0

[root@centos-6-11 ~]# ip add|grep 10.0.0.
    inet 10.0.0.11/24 brd 10.0.0.255 scope global eth0
    inet 10.0.0.30/24 scope global secondary eth0
    inet 10.0.0.31/24 scope global secondary eth0


    server {
        listen       10.0.0.30:80;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       10.0.0.31:8080;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }



4 虚拟主机的别名配置

server {
        listen       80;
        server_name  bbs.zyb.com zyb.com;  #在后面添加即可
        location / {
            root   html/bbs;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }


5 Nginx 状态信息配置

[root@centos-6-11 vhost]# vi status.zyb.com.conf 
server {
        listen       80;
        server_name  status.zyb.com;
        location /status {
                stub_status on;
                access_log off;
            }
    }

测试结果:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值