安装
sudo apt update
sudo apt install nginx
nginx配置文件在/etc/nginx目录下的nginx.conf。在nginx.conf->http选项末尾有引入两个目录下的文件分别为:
http {
# 省略部分内容
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我们查看/etc/nginx/sites-enabled/目录,会找到一个default文件,在server选项下前两行就可以找到使用的80端口号:
server {
listen 80 default_server;
listen [::]:80 default_server;
}
配置nginx反向代理
sudo vi /etc/nginx/conf.d/自己命名.conf;
server {
listen 80; //设置nginx监听的端口
server_name www.wrazd.com; //nginx监听的域名或ip
location / {
proxy_pass http://127.0.0.1;//要代理的目标服务器地址,可加端口
index index.html;
}
location /eaionline {
proxy_pass http://127.0.0.1:8080;
index index.html index.htm index.jsp;
}
location /wxarticle {
proxy_pass http://127.0.0.1:8787;
index index.html index.htm index.jsp;
}
}
注意:
ubuntu系统如果设置了防火墙,需要将用到的端口加入规则里,如果是购买的云服务器,需要注意将对应端口加入安全组策略
查看防火墙状态:sudo ufw status
将端口号加入规则:sudo ufw allow **