[英]node.JS / Django - configure Apache / NGINX to run from location
I am using Apache as my frontend VPS / NGINX as backend VPS for node.js / django apps with react.js frontend.我使用 Apache 作为我的前端 VPS / NGINX 作为 node.js / Z2B9AFB5.9BFJSA6ACCD10ADZB 应用程序的后端 VPS 前端。
I am trying to run my apps from same VPS, but from different locations: eg:我正在尝试从相同的 VPS 但从不同的位置运行我的应用程序:例如:
https://myapps/app1
https://myappps/app2
Previously I have tackled this issue by adding the location in the router of the apps - however I am not sure if this is the best way to do this.以前我通过在应用程序的路由器中添加位置来解决这个问题 - 但是我不确定这是否是最好的方法。 Can I actually add the location in the VPS config of NGINX or Apache?我真的可以在 NGINX 或 Apache 的 VPS 配置中添加位置吗?
# nginx.default
server {
listen 8020;
server_name example.org;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
root /opt/app/client/build/;
}
}
If you are running two node apps it could be done using this NGINX config.如果您正在运行两个节点应用程序,则可以使用此 NGINX 配置来完成。 Just make sure app1 and app2 are on different ports.只要确保 app1 和 app2 在不同的端口上。
server {
listen 80;
server_name localhost;
location /app1 {
proxy_pass http://127.0.0.1:5000;
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;
}
location /app2{
proxy_pass http://127.0.0.1:5001;
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;
}
}
EDIT: This is how I have multiple sites running *note: server name should be set to the domain, but if you dont have access to domains set them as the IP:PORT shown in example below.编辑:这就是我运行多个站点的方式 *注意:服务器名称应设置为域,但如果您无权访问域,请将它们设置为 IP:PORT,如下例所示。 Reason why server name cannot be local is it needs to be public for access.服务器名称不能是本地名称的原因是它需要公开才能访问。 In my use case for website 1 server_name is website1.com then website 2 server_name is website2.com (My domains)在我的网站 1 server_name 的用例中,网站 1 server_name 是 website1.com 然后网站 2 server_name 是 website2.com(我的域)
server {
listen 5000;
//APP 1
server_name 10.0.0.1:5000;
location /{
proxy_pass http://127.0.0.1:5000;
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;
}
}
server {
listen 5001;
//APP 2
server_name 10.0.0.1:5001;
location /{
proxy_pass http://127.0.0.1:5001;
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.