2013-09-27 47 views
0

我正在部署一個帶有jar文件的網站。這是我設置的第一臺服務器,所以我在這裏做了些什麼,但有點失落。我在我的nginx.config中有:嘗試www到no-www時inginx失敗

server{ 
    listen   80; 
    server_name  www.mySite.com; 
    return   301 $scheme://mySite.com$request_uri; 
} 

server { 
    listen  80; 
    server_name mySite.com; 

     location/{ 
      proxy_pass http://localhost:3000 ; 
     } 

     ..... 

我根據文檔設置了CNAME。

我已經試過了很多資源,理順了這一點:

http://nginx.org/en/docs/http/converting_rewrite_rules.html

Nginx no-www to www and www to no-www

http://rtcamp.com/wordpress-nginx/tutorials/nginx/www-non-www-redirection/

而繼續得到同樣的錯誤:

$ systemctl status nginx.service 
nginx.service - A high performance web server and a reverse proxy server 
    Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled) 
    Active: failed (Result: exit-code) since Fri 2013-09-27 06:22:30 UTC; 11s ago 
    Process: 4492 ExecStop=/usr/bin/nginx -g pid /run/nginx.pid; -s quit (code=exited, status=1/FAILURE) 
    Process: 3705 ExecStart=/usr/bin/nginx -g pid /run/nginx.pid; daemon on; master_process on; (code=exited, status=0/SUCCESS) 
    Process: 4495 ExecStartPre=/usr/bin/nginx -t -q -g pid /run/nginx.pid; daemon on; master_process on; (code=exited, status=1/FAILURE) 
Main PID: 3706 (code=exited, status=0/SUCCESS) 
    CGroup: name=systemd:/system/nginx.service 

回答

0

我找到了解決方案。原來,我並不需要添加第二個服務器:

server { 
    listen  80; 
    server_name mySite.com www.mySite.com; 

     location/{ 
      proxy_pass http://localhost:3000 ; 
     } 

我不知道,如果這個絕對正確的答案,但我也嘗試從nginx.com這個例子,但是沒有工作:

server { 
    listen  80; 
    server_name example.com www.example.com; 
    ... 
} 

server { 
    listen  80 default_server; 
    server_name _; 
    return  301 http://example.com$request_uri; 
}