【发布时间】: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 找不到服务器”