1 回答

TA貢獻1934條經驗 獲得超2個贊
nginx綁定多個域名可又把多個域名規則寫一個配置文件里,也可又分別建立多個域名配置文件,我一般為了管理方便,每個域名建一個文件,有些同類域名也可又寫在一個總的配置文件里。一、每個域名一個文件的寫法 首先打開nginx域名配置文件存放目錄:/usr/local/nginx/conf/servers ,如要綁定域名www.rodine.org 則在此目錄建一個文件:www.rodine.org.conf然后在此文件中寫規則,如:server
1 2 3 4 5 6 7 | { listen 80; server_name www.rodine.org; #綁定域名 index index.htm index.html index.php; #默認文件 root /home/www/rodine.org; #網站根目錄 include location.conf; #調用其他規則,也可去除 } |
然后重起nginx服務器,域名就綁定成功了nginx服務器重起命令:/etc/init.d/nginx restart二、一個文件多個域名的寫法一個文件添加多個域名的規則也是一樣,只要把上面單個域名重復寫下來就ok了,如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | server { listen 80; server_name www.rodine.org; #綁定域名 index index.htm index.html index.php; #默認文件 root /home/www/rodine.org; #網站根目錄 include location.conf; #調用其他規則,也可去除 }server { listen 80; server_name msn.rodine.org; #綁定域名 index index.htm index.html index.php; #默認文件 root /home/www/msn.rodine.org; #網站根目錄 include location.conf; #調用其他規則,也可去除 } |
三、不帶www的域名加301跳轉如果不帶www的域名要加301跳轉,那也是和綁定域名一樣,先綁定不帶www的域名,只是不用寫網站目錄,而是進行301跳轉,如:
1 2 3 4 5 6 | server { listen 80; server_namerodine.org; rewrite ^/(.*) http://www.rodine.org/$1 permanent; } |
四、添加404網頁
添加404網頁,都可又直接在里面添加,如:
1 2 3 4 5 6 7 8 9 | server { listen 80; server_name www.rodine.org; #綁定域名 index index.htm index.html index.php; #默認文件 root /home/www/rodine.org; #網站根目錄 include location.conf; #調用其他規則,也可去除 error_page 404 /404.html; } |
學會上面四種規則方法,基本就可以自己獨立解決nginx 多域名配置問題了
- 1 回答
- 0 關注
- 779 瀏覽
添加回答
舉報