Nginx配置反向代理。css
準備兩臺服務器jquery
http://192.168.70.66
http://192.168.70.62
設置正則匹配(192.168.70.66)nginx
vim /usr/local/nginx/conf/nginx.conf
增長vim
location ~ .*\.(js|css)$ { proxy_pass http://192.168.70.62:80; proxy_set_header X-Forwarded-For $remote_addr; }
重啓服務器
nginx -s reload
設置日誌(192.168.70.62)代理
vim /usr/local/nginx/conf/nginx.conf
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main;
nginx -s reload
訪問日誌
http://192.168.70.66/public/static/ace1.4/assets/js/jquery-2.1.4.min.js
其實這個時候已經訪問的是code
http://192.168.70.62/public/static/ace1.4/assets/js/jquery-2.1.4.min.js
將66下的js刪除,同樣能夠訪問。可是將62下的js刪除,就不能訪問了。orm
下面是62下的日誌信息。rem
cat /usr/local/nginx/logs/access.log
192.168.70.66 - - [11/Jan/2018:19:30:19 -0800] "GET /public/static/ace1.4/assets/js/jquery-2.1.4.min.js HTTP/1.0" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3298.4 Safari/537.36" "192.168.70.33"
來自66的訪問,可是實際上是33物理機的訪問。
這就是反向代理的基本狀況。