Bra*_*son 6 apache reverse-proxy node.js
我一直在互联网上搜索一周,试图找到一个很好的解决方案.首先我读了一下http-master,但我一直遇到安装问题.然后我看到了其他一些没有配置功能和易用性的产品.或者答案都已过时了
我们想在NodeJS中开发网站,目前有三个,两个用于测试/开发,一个用于生产.其中每个都托管在同一台服务器上,目前是具有相同域名但端口不同的Apache服务器.我们还有另一个网站,我们正在使用不同的域名.
问题是,使用NodeJS为所有站点提供服务的最佳方式是什么?展望未来,我们希望开发NodeJS中的所有应用程序.
服务器规格:Windows Server 2012 R2两核4 GB RAM
您想使用反向代理.nginx是一个不错的选择,因为配置非常简单.但是使用apache也可以实现同样的目的.
基本上,您只需在不同的端口下运行每个应用程序,并基于请求的域名代理.这是使用nginx的示例设置.
## Upstream www.example.com ##
upstream examplelive {
server 8081; # nodejs server running on port 8081
}
## Upstream dev.example.com ##
upstream exampledev {
server 8082; # nodejs server running on port 8082
}
## www.example.com ##
server {
listen 80;
server_name www.example.com;
access_log /var/log/nginx/log/www.example.access.log main;
error_log /var/log/nginx/log/www.example.error.log;
## send request back to examplelive ##
location / {
proxy_pass http://examplelive;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
## dev.example.com ##
server {
listen 80;
server_name dev.example.com;
access_log /var/log/nginx/log/dev.example.com.access.log main;
error_log /var/log/nginx/log/dev.example.com.error.log;
location / {
proxy_pass http://exampledev;
proxy_set_header Host static.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Run Code Online (Sandbox Code Playgroud)
下面的apache示例应该可行.
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName www.example.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:8081/
ProxyPassReverse http://localhost:8081/
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@dev.example.com
ServerName dev.example.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:8082/
ProxyPassReverse http://localhost:8082/
</Location>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1777 次 |
| 最近记录: |