【问题标题】:how to redirect www to http with nginx如何使用 nginx 将 www 重定向到 http
【发布时间】:2019-03-23 00:45:03
【问题描述】:

我有一个在服务器上运行的节点 Web 应用程序。我正在使用 pm2 运行该应用程序,该应用程序在 localhost:3000 上运行。我的 nginx 配置文件位于 /etc/nginx/sites-available/default,如下所示:

server {
    listen 80 default_server;
    listen [::]:80 default_server;



    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {

            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }


}

当我转到http://example.com 时,该站点可以正常工作,但是当我转到 www.example.com 时,浏览器显示无法打开页面,找不到服务器。

如何让 nginx 配置(或其他东西)将 www 请求重定向到 http?

【问题讨论】:

  • 实际的错误信息是什么?,因为您提到的那个听起来您没有正确设置 DNS
  • @LawrenceCherone 实际消息是“Safari 找不到服务器”

标签: node.js nginx server


【解决方案1】:

您不必像这样输入 server_name:

server_name example.com www.example.com

【讨论】:

  • _ 是默认值,即所有不匹配
猜你喜欢
  • 1970-01-01
  • 2016-01-07
  • 2018-02-02
  • 1970-01-01
  • 2014-05-08
  • 2017-09-03
  • 2015-10-23
  • 2014-02-02
  • 1970-01-01
相关资源
最近更新 更多