[乐意黎] 通过Apache代理访问NodeJS服务

1. 通过 80端口访问

在 /etc/httpd/httpd.conf里添加如下配置, 注, 未在 .htacess 中做任何设置

[html]  view plain  copy
 print ?
  1.  <VirtualHost *:80>  
  2. 226   ServerName wxapi-node.aerchi.com  
  3. 227   ServerAlias wxapi-node.aerchi.com 
  4. 228   ProxyRequests off  
  5. 229  
  6. 230   # DocumentRoot /usr/local/apache/htdocs  
  7. 231  
  8. 232   <Directory />  
  9. 233       Options -Indexes +FollowSymLinks  
  10. 234       AllowOverride None  
  11. 235       Require all granted  
  12. 236    </Directory>  
  13. 237  
  14. 238    ProxyRequests Off  
  15. 239    ProxyPreserveHost On  
  16. 240    ProxyVia Full  
  17. 241    <Proxy *>  
  18. 242       Require all granted  
  19. 243    </Proxy>  
  20. 244  
  21. 245   <Location />  
  22. 246     ProxyPass http://localhost:3389/  
  23. 247     ProxyPassReverse http://localhost:3389/  
  24. 248   </Location>  
  25. 249 </VirtualHost>  


Nodejs 中设置如下, 

[html]  view plain  copy
 print ?
  1. var http = require('http');  
  2. var port = 3389;  
  3. http.createServer(app).listen(port, function(req, res){  
  4.     // res.writeHead(200);  
  5.     console.log('server is running on port '+port);  
  6. });  



2. 通过 443端口访问


[html]  view plain  copy
 print ?
  1. 4 # 2017-06-16  
  2. 225 <VirtualHost *:80>  
  3. 226   ServerName wxapi-node.aerchi.com  
  4. 227   ServerAlias wxapi-node.aerchi.com  
  5. 228   ProxyRequests off  
  6. 229  
  7. 230  # DocumentRoot /usr/local/apache/htdocs/app-node  
  8. 231  
  9. 232   <Directory />  
  10. 233       Options -Indexes +FollowSymLinks  
  11. 234       AllowOverride None  
  12. 235       Require all granted  
  13. 236    </Directory>  
  14. 237  
  15. 238    ProxyRequests Off  
  16. 239    ProxyPreserveHost On  
  17. 240    ProxyVia Full  
  18. 241    <Proxy *>  
  19. 242       Require all granted  
  20. 243    </Proxy>  
  21. 244  
  22. 245   <Location />  
  23. 246     ProxyPass https://localhost:3389/  
  24. 247     ProxyPassReverse https://localhost:3389/  
  25. 248   </Location>  
  26. 249 </VirtualHost>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值