#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; server_tokens off; sendfile on; #tcp_nopush on; client_max_body_size 5m; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80 default_server; listen 8888 default_server; server_name _; return 444; } server { listen 8888; server_name oa.shiyi.tv oa.brawin.cn; #强制转HTTPS #rewrite ^(.*)$ https://$host$1 permanent; #强制域名访问 # if ($host != oa.shiyi.tv) { # return 403; # } #charset koi8-r; #access_log logs/host.access.log main; #禁止Scrapy等爬虫工具的抓取,如果用到百度收录,这里就要注释掉 if ($http_user_agent ~* "Scrapy|Sogou web spider|Baiduspider") { return 403; } #禁止指定UA及UA为空的访问 if ($http_user_agent ~ "FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|LinkpadBot|Ezooms|^$"){ return 403; } #禁止非GET|HEAD|POST方式的抓取,此处可能会导致网页打不开 #if ($request_method !~ A(GET|HEAD|POST)$) { # return 403; # } #针对特殊的user_agent的访问 if ($http_user_agent ~ "Mozilla/4.0\ \(compatible;\ MSIE\ 6.;\ Windows\ NT\ 5.1;\ SV1;\ .NET\ CLR\ 1.1.4322;\ .NET\ CLR\ 2.0.50727\)") { return 404; } proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header Host $host; proxy_set_header Upgrade-Insecure-Requests 1; proxy_set_header X-Forwarded-Proto https; proxy_read_timeout 300; location / { root html; index index.html index.htm; proxy_pass http://192.168.1.91:80; 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; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name oa.shiyi.tv oa.brawin.cn; #强制转HTTPS #rewrite ^(.*)$ https://$host$1 permanent; #强制域名访问 # if ($host != oa.shiyi.tv) { # return 403; # } #charset koi8-r; #access_log logs/host.access.log main; #禁止Scrapy等爬虫工具的抓取,如果用到百度收录,这里就要注释掉 if ($http_user_agent ~* "Scrapy|Sogou web spider|Baiduspider") { return 403; } #禁止指定UA及UA为空的访问 if ($http_user_agent ~ "FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|LinkpadBot|Ezooms|^$"){ return 403; } #禁止非GET|HEAD|POST方式的抓取,此处可能会导致网页打不开 #if ($request_method !~ A(GET|HEAD|POST)$) { # return 403; # } #针对特殊的user_agent的访问 if ($http_user_agent ~ "Mozilla/4.0\ \(compatible;\ MSIE\ 6.;\ Windows\ NT\ 5.1;\ SV1;\ .NET\ CLR\ 1.1.4322;\ .NET\ CLR\ 2.0.50727\)") { return 404; } proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header Host $host; proxy_set_header Upgrade-Insecure-Requests 1; proxy_set_header X-Forwarded-Proto https; proxy_read_timeout 300; location / { root html; index index.html index.htm; proxy_pass http://192.168.1.91:80; 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; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }