[英]Node.js on port 80
我在Node.js中有一个在端口3010(domain.com:3010)上运行的应用程序。 是否可以使其在端口80(domain.com)上运行?
我有一台带有CentOS的VPS服务器。 我搜索了很多但没有任何效果。
您可以按照本文所述创建虚拟主机
<VirtualHost *:80>
ServerName node.mydomain.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3010/
ProxyPassReverse http://localhost:3010/
</Location>
</VirtualHost>
IMO最好在Node.js前使用Nginx而不是Apache。 配置示例(我的/etc/nginx/conf.d/default.conf
文件)
upstream my-node-app {
server 127.0.0.1:3000;
}
server {
listen 80 default_server;
#server_name _;
server_name www.domain.com domain.com;
access_log /var/log/nginx.access.log main;
location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
proxy_pass http://127.0.0.1:3000/;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
您可以更改应用程序配置中的端口,或将端口配置为在路由器中根据需要进行响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.