使用 NGINX 将端口 80 转发到 8080 [英] Forwarding port 80 to 8080 using NGINX

查看:62
本文介绍了使用 NGINX 将端口 80 转发到 8080的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 debian 服务器上使用 LEMP 堆栈和 Node JS.Nginx 在 80 端口和 8080 上的 Node JS 上工作.我为 nodejs 应用程序创建了新的子域:cdn.domain.com.目前我只能像 cdn.domain.com:8080/一样访问 Node JS 应用程序.我想要做的是配置 Nginx,这样当我进入 cdn.domain.com 时,我可以让应用程序在端口 80 上工作.我认为可以使用上游 nginx 来完成.但我无法弄清楚如何.

I'm using LEMP stack and Node JS on my debian server. Nginx works on port 80 and Node JS on 8080. I created new subdomain: cdn.domain.com for nodejs app. Currently I can access to Node JS application only like cdn.domain.com:8080/. What I want to do is to configure Nginx so that, when I enter to cdn.domain.com I can get app working on port 80. I think it can be done using nginx upstream. But I can't figure out how.

推荐答案

就这么简单,

确保将 example.com 更改为您的域(或 IP),并将 8080 更改为您的 Node.js 应用程序端口:

make sure to change example.com to your domain (or IP), and 8080 to your Node.js application port:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         "http://127.0.0.1:8080";
    }
}

来源:https://eladnava.com/binding-nodejs-port-80-using-nginx/

这篇关于使用 NGINX 将端口 80 转发到 8080的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆