首页 > 解决方案 > nginx 虚拟主机在本地工作但不在全球范围内工作

问题描述

当我在本地主机上使用 curl 它的工作。

root@ip-10-87-3-236:/etc/nginx# curl -o /dev/null -s -w "%{http_code}\n" http://localhost/ib

Output :

200

但是当我通过互联网连接到浏览器时,我得到了

Not Found
The requested resource was not found on this server.

nginx 配置:

server {
    listen 80;
    server_name localhost;
    location /ib {
        proxy_pass http://localhost:3000; #whatever port your app runs on
        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;
    }
    
}

请在此处提供帮助或分享任何可能非常有用的文档

谢谢

标签: nginxhostingvirtual

解决方案


您已指定localhost为您的server_name. 如果您想通过 Internet 和/或使用您选择的域名进行这项工作,例如example.com将 设置server_name为域名。这将解决您的问题。

参考:https ://nginx.org/en/docs/http/ngx_http_core_module.html#server_name


推荐阅读