我如何在 openSUSE 上使用 NGINX 或 Apache2 将我的端口 80 重新路由到 localhost:3000 以便我可以 运行 我的 Node.js 应用程序
How do I use NGINX or Apache2 on openSUSE to re-route my port 80 to localhost:3000 so I can run my Node.js app
如问题陈述所述,我是运行openSUSE(leap 42.3)。我在 localhost:3000
上有一个节点应用程序 运行,我想发布它(让我的网络之外的人可以使用它)。我已经有一个域,目前,文件由端口 80 上的 apache2 提供服务。我在网上发现了大量类似的问题和解决方案,但是 none 是我特有的(我认为这是因为操作系统)。任何人都可以逐步解决我必须做的事情吗?
我找到的第一个解决方案告诉我更改配置文件,这就是我现在拥有的:
<VirtualHost *:80>
ServerName test.mytestsitebyrichard.com
ServerAlias *.test.mytestsitebyrichard.com
DocumentRoot /srv/www/htdocs
#ProxyRequests on <--currently commented but this is what online tutorials told me to do. However, it is crashing the apache2
#ProxyPass /cs/ http://localhost:3000/
</VirtualHost>
我需要启用什么吗?我已经从配置菜单中启用了 ProxyPass
和 ProxyPassReverse
。任何帮助,将不胜感激。谢谢。
注意请参考以下截图:
您可以使用反向代理在 Nginx 中实现此目的。
在您的 /etc/nginx/sites-enabled/
目录中添加具有以下配置的新配置文件(例如 myapp.conf
):
server {
listen 80;
server_name yoururl.com;
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;
}
}
如问题陈述所述,我是运行openSUSE(leap 42.3)。我在 localhost:3000
上有一个节点应用程序 运行,我想发布它(让我的网络之外的人可以使用它)。我已经有一个域,目前,文件由端口 80 上的 apache2 提供服务。我在网上发现了大量类似的问题和解决方案,但是 none 是我特有的(我认为这是因为操作系统)。任何人都可以逐步解决我必须做的事情吗?
我找到的第一个解决方案告诉我更改配置文件,这就是我现在拥有的:
<VirtualHost *:80>
ServerName test.mytestsitebyrichard.com
ServerAlias *.test.mytestsitebyrichard.com
DocumentRoot /srv/www/htdocs
#ProxyRequests on <--currently commented but this is what online tutorials told me to do. However, it is crashing the apache2
#ProxyPass /cs/ http://localhost:3000/
</VirtualHost>
我需要启用什么吗?我已经从配置菜单中启用了 ProxyPass
和 ProxyPassReverse
。任何帮助,将不胜感激。谢谢。
注意请参考以下截图:
您可以使用反向代理在 Nginx 中实现此目的。
在您的 /etc/nginx/sites-enabled/
目录中添加具有以下配置的新配置文件(例如 myapp.conf
):
server {
listen 80;
server_name yoururl.com;
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;
}
}