1. 配置语法
Syntax: proxy_pass URL;
Default: -
Context: location, if in action, limit_except
2. 配置代理服务器
[root@VM_0_15_centos code2]# vim /etc/nginx/conf.d/fx_proxy.conf
server {
listen 80;
server_name localhost;
location / {
root /opt/app/code;
index index.html index.htm;
}
location ~ /test_proxy.html$ {
proxy_pass http://127.0.0.1:8080;
}
}
3. 配置被代理(真实)服务器
[root@VM_0_15_centos code2]# vim /etc/nginx/conf.d/realserver.conf
server {
listen 8080;
server_name localhost;
location / {
root /opt/app/code2;
index index.html index.htm;
}
}
4. 重载nginx服务器
nginx -s relead -c /etc/nginx/nginx.conf
5. 查看nginx占用了哪些端口
[root@VM_0_15_centos code2]# netstat -luntp|grep nginx
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 10063/nginx: master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10063/nginx: master
6. 测试
浏览器访问http://119.28.190.215/test_proxy.html,看到8080端口下的test_proxy.html,测试成功。