nginx及apache代理pm2启动的node程序
发布于 作者:苏南大叔 来源:程序如此灵动~
本篇文章里面,苏南大叔这里就是炒炒冷饭了。对于nginx
或者apache
,"通过pm2启动node网站" 对比 "通过php-fpm启动php网站",其实几乎没有太大区别。所以,这里就是老瓶子装新酒了。不同的是:php-fpm
只占用一个端口,node
则可能会占用无数个端口。
nginx的vhost配置demo
mac
下的默认位置是:/usr/local/etc/nginx/servers/
server {
listen 80;
server_name newsn.net;
root <your/project/path/>
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://127.0.0.1:3000;
proxy_redirect default;
}
}
apache的配置demo
mac
下的默认位置是:/etc/apache2/
<VirtualHost *:80>
ServerName newsn.net
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://127.0.0.1:3000/
ProxyPassReverse http://127.0.0.1:3000/
</Location>
</VirtualHost>
当然,在apache
下,还需要在httpd.conf
里面,打开如下类似配置:
LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
Include /private/etc/apache2/extra/httpd-vhosts.conf
配置完pm2
,再如此配置完nginx
之后,nodejs
搭建的网站才算真正部署完毕。是不是累出一身大汗的节奏。
结论
欢迎关注苏南大叔的相关node
精彩经验分享: https://newsn.net/tag/node/ 。


