现需要给一台Web服务器在Nginx服务器上添加反向代理配置,web服务器需求反代的url为aabbced.com/erc,需要在浏览器端通过/erc来访问实际的/cfscf目录
解决方案
写nginx反代配置文件:
server {
listen 80;
listen 443 ssl;
server_name $Domain;
#Domain是指域名,例如需求中的aabbced.com
ssl_certificate xxx;
ssl_certificate_key xxxxxxxxxxxxxx;
#ssl证书文件
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
#ssl证书密码
ssl_prefer_server_ciphers on;
location / {
proxy_pass $Domain;
#一般为主站点所以Domain一般也是aabbced.com,二般情况二般讨论
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log $log_file.log main;
}
location ^~ /$URL_DIR/ {
proxy_pass $Domain.$URL_DIR/$REAL_DIR;
#URL_DIR就是url中的目录,REAL_DIR就是Web服务器真实目录
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log $log_file1.log main;
}
}
upstream $Domain {
server $HOSTNAME:$PORT;
}
upstream $Domain.$REAL_DIR{
server $HOSTNAME:$PORT1;
--------------------------------------分割线 --------------------------------------
CentOS 6.2实战部署Nginx+MySQL+PHP
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程
CentOS 6.3下配置Nginx加载ngx_pagespeed模块