2016-12-15 140 views
0

我使用laravel nginx的開拓,我試圖顯示域www.example.com,而不是example.comNGINX域名WWW防止重定向

在我的帳戶一些較舊的配置,我能夠顯示這兩個版本的網址上的內容,但最近我配置一個網站時,它重定向www。版本到根版本。反正有禁用這種行爲。

# FORGE CONFIG (DOT NOT REMOVE!) 
include forge-conf/example.com/before/*; 
server { 
    listen 80; 
    listen [::]:80; 
    server_name .www.example.com .example.com; 
    root /home/forge/example.com/site/web; 
    # FORGE SSL (DO NOT REMOVE!) 
    # ssl_certificate 
    # ssl_certificate_key 
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA'; 
    ssl_prefer_server_ciphers on; 
    ssl_dhparam /etc/nginx/dhparams.pem; 
    index index.html index.htm index.php; 
    charset utf-8; 
    # FORGE CONFIG (DOT NOT REMOVE!) 
    include forge-conf/example.com/server/*; 
    location/{ 
     try_files $uri $uri/ /index.php?$query_string; 
    } 
    location = /favicon.ico { access_log off; log_not_found off; } 
    location = /robots.txt { access_log off; log_not_found off; } 
    access_log off; 
    error_log /var/log/nginx/example.com-error.log error; 
    error_page 404 /index.php; 
    location ~ \.php$ { 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
    } 
    location ~ /\.ht { 
     deny all; 
    } 
} 
# FORGE CONFIG (DOT NOT REMOVE!) 
include forge-conf/example.com/after/*; 
+1

你的問題是'是否有禁止這種行爲'和答案是**是的,有一種方法**。爲什麼我輸入這樣的回答?我做到了,所以你可以看到當你尋求幫助並且你沒有提供代碼時會發生什麼。爲了得到你可以使用的答案,要求修改你的問題。 – Mjh

+0

@Mjh你已經注意到了,我在代碼中添加了,謝謝。 – Davidaj

回答

1

您需要使用網址www.example.com而不是example.com創建您的網站,以實現您期望的網址結構。

+0

這工作,謝謝 – Davidaj