2024年08月23日 建站教程
反向代理服务器可以帮助我们实现负载均衡、高可用性和安全性。使用NGINX和PM2在VPS服务器中配置反向代理是一个非常常见的场景。下面web建站小编给大家简单介绍一下具体实现方法!
1、安装NGINX和PM2
# 安装NGINX sudo apt-get install nginx # 安装PM2 npm install -g pm2
2、配置NGINX
# 打开默认NGINX配置文件
sudo nano /etc/nginx/sites-available/default
# 在文件中添加以下配置
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:3000;
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;
}
}
3、启动PM2应用
# 启动应用 pm2 start app.js
4、启动NGINX和PM2
# 启动NGINX sudo service nginx start # 启动PM2 pm2 save pm2 startup
5、配置防火墙(可选)
# 允许特定IP地址(your_ip_address)访问服务器 sudo ufw allow from your_ip_address to any port 80
本文链接:http://so.lmcjl.com/news/11509/