0

我正在部署一个带有 jar 文件的网站。这是我设置的第一台服务器,所以我对在这里做什么有点迷茫。我的 nginx.config 中有这个:

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 到 www 和 www 到 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
4

1 回答 1

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;
}
于 2013-09-28T01:40:16.157 回答