日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

目錄
  • 為什么要給nginx配置rewrite?
  • 錯誤原因
  • 解決方案
  • 重啟nginx服務(wù)器

為什么要給nginx配置rewrite?

因為公司要求訪問 shidongyun.com的時候瀏覽器會自動跳轉(zhuǎn)到www.shidong.com下面,專業(yè)術(shù)語叫“301跳轉(zhuǎn)”百度了一番,nginx配置規(guī)則,用rewrite還有return進行重寫301跳轉(zhuǎn)。我這里用的是rewrite。

nginx配置完rewrite瀏覽器提示將您重定向的次數(shù)過多的解決方法

錯誤原因

在配置網(wǎng)站站點的時候service里面的service_name 規(guī)則不正確。錯誤配置規(guī)則如下:

只看service這部分錯誤的即可。service_name 不能把rewrite即將要重寫的域名寫進去,這樣就造成了死循環(huán)了。比如:我要訪問"shidongyun.com",利用rewrite在瀏覽器輸入“shidongyun.com”的時候,重寫到www.shidongyun.com下面。那么在service_name就不能寫www.shidongyun.com這個域名。可以單獨寫一個service,也可以不用寫。直接這樣寫:rewrite ^/(.*) http://www.shidongyun.com/$1 permanent;。

server {
    listen       80;
    server_name www.shidongyun.com shidongyun.com;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    root    "/data/wwwroot/shidong";
    location / {
        rewrite ^/(.*) http://www.shidongyun.com/$1 permanent;
        index  index.html index.htm index.php l.php;
        try_files $uri $uri/ /index.php?$query_string;
       autoindex  off;
    }

解決方案

1,把service下面的service_name 做正確的修改,刪除www.shidongyun.com這個要重寫的域名。

server {
    listen       80;
    server_name shidongyun.com;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    root    "/data/wwwroot/shidong";
    location / {
        rewrite ^/(.*) http://www.shidongyun.com/$1 permanent;
        index  index.html index.htm index.php l.php;
        try_files $uri $uri/ /index.php?$query_string;
       autoindex  off;
    }

在次在瀏覽器訪問:shidongyun.com,我們看到截圖中已經(jīng)成功的重寫過去了。但是訪問域名的時候默認找的是網(wǎng)站安裝時候的目錄。并不是項目目錄。解決方案如下:

nginx配置完rewrite瀏覽器提示將您重定向的次數(shù)過多的解決方法

2,需要配置rewrite重定向到指定的目錄或者單獨配置一個service虛擬機,然后把需要rewrite重定向的service主機跟域名配置好。配置信息如下:

我們先配置一個service虛擬機,要訪問的域名,比如“shidongyun.com”,然后在配置一個service虛擬機,把要rewrite重寫的域名放進去,比如:“www.shidong.com”,我們達到的效果就是訪問“shidongyun.com”瀏覽器地址會自動跳轉(zhuǎn)到“www.shidongyun,com”下面。

nginx配置完rewrite瀏覽器提示將您重定向的次數(shù)過多的解決方法

nginx配置完rewrite瀏覽器提示將您重定向的次數(shù)過多的解決方法

示例代碼如下:

server {
    listen       80;
    server_name shidongyun.com;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    root    "/data/wwwroot/shidong";
    location / {
        index  index.html index.htm index.php l.php;
        rewrite ^/(.*) http://www.shidongyun.com/$1 permanent;
        try_files $uri $uri/ /index.php?$query_string;
       autoindex  off;
    }
    省略多余的部分.....只需要看rewrite跟service_name即可
}
server {
    listen       80;
    server_name www.shidongyun.com;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    root    "/data/wwwroot/shidong";
    location / {
        index  index.html index.htm index.php l.php;
        try_files $uri $uri/ /index.php?$query_string;
       autoindex  off;
    }
	省略多余的部分.....只需要看service_name即可。root設(shè)置項目路徑。
    }

重啟nginx服務(wù)器

1, /etc/init.d/nginx restart

[root@iZm5e8nyz28v9zr7lhb7moZ ~]# /etc/init.d/nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@iZm5e8nyz28v9zr7lhb7moZ ~]# 

2,瀏覽器輸入“shidongyun.com”自動跳轉(zhuǎn)到“www.shidongyun.com”下面

nginx配置完rewrite瀏覽器提示將您重定向的次數(shù)過多的解決方法

分享到:
標簽:將您 瀏覽器 解決方法 過多 重定向
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運動步數(shù)有氧達人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定