Nginx虛擬主機常用配置(學習筆記四)
1、
upstream test_1633_pool {
server 10.160.51.75:8200 weight=10 max_fails=2 fail_timeout=600s;
server 10.168.246.204:8200 weight=10 max_fails=2 fail_timeout=600s backup;
}
upstream i_1633_pool {
ip_hash;
server 10.160.12.61:8001 weight=10 max_fails=2 fail_timeout=300s;
server 10.160.12.62:8001 weight=10 max_fails=2 fail_timeout=300s;
}
upstream tag_1633_pool {
server 10.160.51.75:8022 weight=10 max_fails=2 fail_timeout=30s;
server 10.168.246.204:8022 weight=10 max_fails=2 fail_timeout=600s down;
}
2、#stub_status開啟狀態檢視
server {
listen 9001;
location ~ /nginx_status {
stub_status on;
access_log off;
allow 117.25.164.2;
allow 117.25.172.106;
allow 127.0.0.1;
deny all;
}
}
3、#負載均衡,重寫
server {
listen 80;
charset utf-8;
server_name xxxx.com;
access_log /usr/local/wwwroot/xxx.log;
if ( $request_uri = “/” ) {
rewrite “/” /index/home/ break;
}
location / {
proxy_set_header Host $host;
proxy_set_header x-real-IP $remote_addr;
proxy_pass http://hr_1633_pool;
}
include drop_sql.conf;
}
4、#permanent重寫
location / {
rewrite ^/(.*)$ http://www.1633.com/jimei/ permanent;
proxy_set_header x-real-IP $remote_addr;
}
5、#圖片檔案快取7天
location ~ .*.(gif|jpg|jpeg|png|bmp|swf|js|apk)$
{
proxy_pass http://10.165.12.250:8002;
expires 7d;
}
6、#rewrite
rewrite ^/service/(.*) /$1 break;
7、#proxy_next_upstream 設定出現500錯誤後,跳轉到另外的伺服器
location / {
proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header;
proxy_set_header Host $host;
rewrite ^/about.shtml http://xxx/bbs/html/mobile/about.html break;
proxy_pass http://10.160.12.63:8007;
proxy_set_header x-real-IP $remote_addr;
if ($request_uri ~ ^/about.shtml) {
rewrite ^/about.shtml /bbs/html/mobile/about.html break;
proxy_pass http://bbs_xx_pool;
}
}
8、#break後繼續執行
location / {
proxy_set_header Host $host;
rewrite ^/$ /web/login.do break;
proxy_pass http://10.132.83.149:8088;
proxy_set_header x-real-IP $remote_addr;
}
9、#ssl配置,監聽443
server {
listen 80;
listen 443 ssl;
listen [::]:80 ipv6only=on;
charset utf-8;
server_name xxx;
server_name xxxxxx;
ssl_certificate /usr/local/nginx/key/lsfwebos.pem;
ssl_certificate_key /usr/local/nginx/key/lsfwebos.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
location / {
proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_pass http://xxxx_pool;
proxy_set_header x-real-IP $remote_addr;
}
include drop_sql.conf;
}
10、#query_string 判斷查詢字串
if ( $query_string ~ “fak=5649380bd13b4701c4099287” ){
rewrite ^/review/ /review/?$query_string last;
}
11、#valid_referers 只允許某些域名的請求
location /upload/ {
valid_referers blocked certify.keyibao.com admin.keyibao.com *.hn51js.gov.cn *.haixia.gov.cn *.xmdxy.gov.cn *.1633.com *.sztat.gov.cn *.tky.gov.cn *.qh1633.com *.ztkj.gov.cn *.lgttc.com *.gctt.gov.cn *.xa1633.com *.hncd1633.com *.xmbio.gov.cn *.jjky.gov.cn *.k8008.com *.xctrm.com *.vtitt.com *.scsttc.com *.pszj.pxkc.com.cn *.zjk.jjkjw.gov.cn *.xmsme.gov.cn *.lnjssc.gov.cn *.xyskj.gov.cn *.hhkc.gov.cn *.fjcctt.cn *.dgiptts.com *.kjzbsc.com *.xmdxy.net.cn *.xmhc-bio.com *.fky.gov.cn *.lystis.cn *.ysqkjy.gov.cn *.gljkfhq.com *.226.34 *.226.34:8003;
if ($invalid_referer) {
return 404;
break;
}
proxy_pass http://10.160.12.66:805;
}
12、#!~ ~
location !^/html/build.html$ {
rewrite (.*) /html/build.html permanent;
}
13、#host引數
location / {
#proxy_set_header Host $host;
if ($host ~ ^policy.test.gov.cn) {
rewrite ^/(.*) /hn51js_G20.shtml break;
proxy_pass http://10.132.61.215:8005;
}
proxy_pass http://10.160.12.65:809;
proxy_set_header x-real-IP $remote_addr;
}
14、#host 防止爬蟲
if ($host = `xxxx.com`) {
rewrite ^(.*)$ http://www.xxxx.com$1 permanent;
}
location = /robots.txt {
if ($http_user_agent !~* “spider|bot|Python-urllib|pycurl”) {
return 403;
}
}
15、#開啟目錄列表
#nginx開啟目錄列表
autoindex on;//自動顯示目錄
autoindex_exact_size off;//人性化方式顯示檔案大小否則以byte顯示
autoindex_localtime on;//按伺服器時間顯示,否則以gmt時間顯示
相關文章
- Nginx虛擬主機配置Nginx
- Nginx虛擬主機VirtualHost配置Nginx
- 學習筆記-虛擬機器筆記虛擬機
- 當年的筆記_apache配置虛擬主機筆記Apache
- 配置nginx多例項(不同於虛擬主機)Nginx
- Nginx配置之基於域名的虛擬主機Nginx
- nginx虛擬主機實戰Nginx
- 虛擬主機上雲筆記(序言)筆記
- JVM學習筆記(四)—— 虛擬機器位元組碼執行引擎JVM筆記虛擬機
- nginx之 nginx虛擬機器配置Nginx虛擬機
- Nginx配置虛擬主機有哪些步驟?linux伺服器入門學習NginxLinux伺服器
- JVM學習筆記五--虛擬機器棧JVM筆記虛擬機
- Java虛擬機器記憶體模型學習筆記Java虛擬機記憶體模型筆記
- 007.Nginx虛擬主機Nginx
- Nginx實戰(一) 虛擬主機Nginx
- nginx多個虛擬主機noinputfilespecifiedNginx
- KVM虛擬化學習筆記筆記
- Nginx 虛擬主機配置的三種方式(基於域名)Nginx
- Tomcat 學習筆記(3) – Host 主機配置Tomcat筆記
- 配置虛擬機器叢集常用設定主機IP操作虛擬機
- [php]apache虛擬主機配置PHPApache
- nginx伺服器配置多個虛擬主機vhost的方法示例Nginx伺服器
- 詳解Nginx 虛擬主機配置的三種方式(基於埠)Nginx
- 詳解Nginx 虛擬主機配置的三種方式(基於IP)Nginx
- 《深入理解java虛擬機器》學習筆記4——Java虛擬機器垃圾收集器Java虛擬機筆記
- 《深入理解java虛擬機器》學習筆記7——Java虛擬機器類生命週期Java虛擬機筆記
- nginx學習筆記(1):配置項的解析Nginx筆記
- Nginx 學習筆記Nginx筆記
- nginx學習筆記Nginx筆記
- Ubuntu apache2配置虛擬主機UbuntuApache
- ubuntu14.04 lnmp nginx 虛擬主機(多站點 多域名) 配置UbuntuLNMPNginx
- nginx基礎篇之虛擬主機實戰Nginx
- 【Python學習筆記】-虛擬環境virtualenvPython筆記
- 虛擬化學習筆記-基礎知識筆記
- 【Nginx】Nginx虛擬vhost配置檔案Nginx
- Django學習筆記四:阿里雲伺服器購買和配置nginxDjango筆記阿里伺服器Nginx
- nginx學習筆記(3):TCP反向代理基本配置Nginx筆記TCP
- OS學習筆記四:同步機制筆記