您的位置:首页 > 运维架构 > Nginx

nginx 简单的配置(nginx.conf)

2017-06-03 13:19 381 查看
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;

            }

    }

测试结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: