How to config multi servers(second domain name server) with one server {} in your nginx.conf

config sample:

server {
    listen       80;
    server_name  ~^(.+)?\.errong\.win$;
    if ($host = errong.win) {
        rewrite ^ http://www.errong.win permanent;
    }

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   vhosts/$1;
        index  index.html index.htm;
    }
}



Explaination:

1. my domain name is "errong.win",you should replace it with yours.
2. "vhosts" is my root directory, you should replace it with yours too.
3. The path tree of your root directory should like:


errong_leng@blogvpn:~/local/nginx$ ls vhosts/ -all
total 16
drwxrwxr-x  4 errong_leng errong_leng 4096 May 18 02:57 .
drwxrwxr-x 12 errong_leng errong_leng 4096 May 18 02:12 ..
drwxrwxr-x  2 errong_leng errong_leng 4096 May 18 03:05 blog
drwxrwxr-x  2 errong_leng errong_leng 4096 May 18 02:42 freevpn
lrwxrwxrwx  1 errong_leng errong_leng    4 May 18 02:54 www -> blog

PS: due to below codes in conf,
    if ($host = errong.win) {
        rewrite ^ http://www.errong.win permanent;
    }

http://errong.win will same as http://www.errong.win.
And I make a soft link of www to blog.

Remember reload your nginx server 
sudo sbin/nginx -s reload 

So http://errong.win and http://www.errong.win will show same website like 
http://blog.errong.win










No comments:

Post a Comment

fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...