Nginx教程

Nginx set指令

本文主要是介绍Nginx set指令,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

nginx set指令

[root@localhost conf.d]# vim /etc/nginx/conf.d/rewrite.conf
server {
        listen 80;
        server_name www.rewrite.com rewrite.com;
        access_log /var/log/nginx/test2-access.log main;
        error_log /var/log/nginx/test2-error.log;
        location /{
                root /html/rewrite;
                index index.html index.htm index.php;
                if ($host ~* "^www.rewrite.com$|^rewrite.com$" ) {
                        break;
                }
                if ($host ~* "^(.*)\.rewrite\.com$" ) {
                        set $user $1;
                        rewrite .* http://www.rewrite.com/$user permanent;
                }
        }

        location /one{
                root /html/rewrite;
                index index.html index.htm index.php;
        }
        location /two{
                root /html/rewrite;
                index index.html index.htm index.php;
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        root /var/www/test;
        }
}

[root@localhost conf.d]# tree /html
/html
└── rewrite
    ├── index.html
    ├── one
    │   └── index.html
    └── two
        └── index.html

这篇关于Nginx set指令的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!