2015-04-21 102 views
0

我想從我的網址在我的nginx配置中去掉www,並瀏覽文檔和堆棧溢出帖子我寫了下面的配置,但它似乎並沒有工作。nginx不剝離www使用重寫

server_name { 
      server_name www.subdomain.domain.com; 
      rewrite ^(.*) https://subdomain.domain.com/$1 permanent 
     } 
server_name { 
      server_name subdomain.domain.com; 

      listen 80 default_server; 
      listen [::]:80 default_server ipv6only=on; 

      root /file; 
      index index.html index.htm app.js; 

      location /{ 

        proxy_pass https://subdomain.domain.com:443/; 
        proxy_redirect off; 
        proxy_set_header Host $host; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

      } 
      location /*/ { 
        proxy_pass https://subdomain.domain.com:443/; 
        proxy_redirect off; 
        proxy_set_header Host $host; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

      } 

     # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests 
     #location /RequestDenied { 
     #  proxy_pass http://127.0.0.1:8080; 
     #} 

     error_page 404 /404.html; 


} 

但它似乎並沒有工作。然而,每當我嘗試去使用www.subdomain.domain.com網站我不能訪問該網站,但做https://subdomain.domain.com工作正常。任何意見,這將是非常感謝。

+0

你有很多語法錯誤。你重新啓動了nginx嗎? –

回答

0

你在nginx的配置(服務器名稱,而不是服務器)錯字,並試圖返回,而不是改寫爲更合適的方式:

server { 
    server_name www.subdomain.domain.com; 
    return 301 $scheme://subdomain.domain.com$request_uri; 
} 
+0

謝謝,但我解決不了。 – Bazinga777