简体   繁体   English

简单地从本地主机:80到本地主机:8080的nginx反向代理不起作用

[英]Simply nginx reverse proxy from localhost:80 to localhost:8080 not working

im learning reverse proxy w/ nginx for the first time, and the following isnt working for me im trying to reroute requests from http://localhost to an api server i have running at http://localhost:8080 我第一次学习带有nginx的反向代理,以下内容对我不起作用,我试图将请求从http:// localhost重新路由到我在http:// localhost:8080运行的api服务器

server {
    listen 80;
    location / {
        proxy_pass http://localhost:8080;
    }
}

when i hit http://localhost , I simply get shown the welcome to nginx splash screen. 当我点击http:// localhost时 ,我只是收到欢迎使用Nginx启动画面的提示。 if i hit http://localhost:8080 , i see my api 如果我点击http:// localhost:8080 ,我会看到我的api

I have a node express service running at :8080, which i can hit manually, but shouldn't http://localhost be proxied there too? 我有一个运行在:8080的节点快递服务,我可以手动打它,但是http:// localhost也不应该被代理吗?

When I setup a nginx domain that forwards requests to a node server, it looks like this, for the server_name , you can use localhost as a parameter for accessing it via localhost. 当我设置将请求转发到节点服务器的nginx域时,对于server_name ,您可以将localhost用作通过localhost访问它的参数。 You can also pass default_server to make this the default server config. 您还可以传递default_server使其成为默认服务器配置。

Note: Only one active config can contain default_server otherwise Nginx will throw errors. 注意:只有一个活动配置可以包含default_server否则Nginx会抛出错误。

Note: When using default_server , Nginx will catch localhost in that server config. 注意:使用default_server ,Nginx将在该服务器配置中捕获localhost Otherwise you need to specify localhost in the list of server_name 's (separated by a space). 否则,您需要在server_name的列表中指定localhost (以空格分隔)。

server {
  # Setup the domain name(s)
  server_name example.com;
  listen 80 default_server;

  # If you would like to gzip your stuff
  gzip on;
  gzip_min_length 1;
  gzip_types *;

  # Setup the proxy
  # This will forward all requests to the server
  # and then it will relay the servers response back to the client
  location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_cache_bypass $http_upgrade;
  }
}

Found out that adding this to my nginx.conf fixes the issue: 发现将其添加到我的nginx.conf中可以解决此问题:

listen [::]:80;

For some reason listen 80; 出于某种原因, listen 80; doesn't catch my http://localhost requests. 无法捕获我的http:// localhost请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Nginx反向代理不适用于本地主机上的Nodejs - Nginx Reverse Proxy not working with Nodejs at localhost http:// localhost:8080 /无效 - http://localhost:8080/ is not working 本地主机:8080不适用于节点服务器 - localhost:8080 not working for node server Nodejs http://localhost:8080 不工作 - Nodejs http://localhost:8080 not working 通过NGINX(localhost)在端口80上运行Ghost - Running Ghost on port 80 through NGINX (localhost) 尝试将请求 /api/v1/mega/building 从 localhost:4200 代理到 http://localhost:8080 时发生错误(ECONNREFUSED) - Error occurred while trying to proxy request /api/v1/mega/building from localhost:4200 to http://localhost:8080 (ECONNREFUSED) Reactjs 代理 [HPM] 尝试将请求从 localhost:8080 代理到 https://localhost:8443/test UNABLE_TO_GET_ISSUER_CERT_LOCALLY 时出错 - Reactjs proxy [HPM] Error occurred while trying to proxy request from localhost:8080 to https://localhost:8443/test UNABLE_TO_GET_ISSUER_CERT_LOCALLY 从http:// localhost:8080请求时,Apache服务器方法不允许 - Apache server Method Not Allowed when requesting from http://localhost:8080 在localhost 8080上找不到Express应用 - Express app not found on localhost 8080 节点如何将网址从c:\\\\ Projects \\\\ a \\转换为localhost:8080 / uploads / - node how to convert url from c:\\Projects\\a\ to localhost:8080/uploads/
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM