开发者

General /etc/nginx/vhosts/default - how to specify server wide settings?

From what I see if I write in the /etc/nginx/vhosts/default the effect will be server wide contrary 开发者_StackOverflow社区to per domain confs. I can't seem to know how to write a rule to redirect from /index.html or /dir/index.html ro / or /dir/ to have server wide effects.

The thing is that running on CentOS makes files in /home/user/public_html and from nginx I can't see the user part to use it in the root directive. I thought of something like this:

---
server
{
listen 111.111.111.111:80;           // fake IP
server_name "";                      // this to take in all hosts... ??
root ~^/home/(.*)/public_html;       // this (.*) would contain the user part
rewrite ^(.*/)index.(html|htm) http://$host$1 permanent;
}
---

As you can see.. probably.. I'm trying to make that redirect work for all sites without having to manually edit each specific per domain conf file but rather have it in the /etc/nginx/vhosts/default conf file.

Any help is much appreciated :)

Thank you


You probably need something like this

server {
    server_name   ~^(www\.)?(?<user>.+)\.domain\.com$;

    location / {
        root  /home/$user/public_html;
    }
}

Also, you can't use regexes in root cause it's a definition not a match.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜