246 lines
9.1 KiB
Plaintext
246 lines
9.1 KiB
Plaintext
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=localhost:100m inactive=60m;
|
|
fastcgi_cache_key "$scheme$request_method$host$request_uri";
|
|
fastcgi_cache_use_stale error timeout invalid_header http_500;
|
|
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
|
|
|
|
map $http_x_forwarded_proto $fcgi_https {
|
|
default off;
|
|
https on;
|
|
}
|
|
|
|
server {
|
|
listen 0.0.0.0:80;
|
|
root /var/www/html;
|
|
|
|
index index.php index.html index.htm;
|
|
|
|
client_max_body_size 512M;
|
|
|
|
proxy_read_timeout 300;
|
|
proxy_connect_timeout 300;
|
|
proxy_send_timeout 300;
|
|
|
|
# HEADERS
|
|
add_header X-Content-Type-Options nosniff;
|
|
add_header X-Xss-Protection "1; mode=block" always;
|
|
add_header X-Robots-Tag all;
|
|
add_header X-Download-Options noopen;
|
|
add_header X-Permitted-Cross-Domain-Policies none;
|
|
add_header Referrer-Policy no-referrer-when-downgrade always;
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
|
|
set_real_ip_from 10.0.12.0/24;
|
|
real_ip_header X-Forwarded-For;
|
|
real_ip_recursive on; # optional but recommended when there can be multiple proxies
|
|
|
|
# location = /robots.txt {
|
|
# allow all;
|
|
# log_not_found off;
|
|
# access_log off;
|
|
# }
|
|
|
|
location = /robots.txt {
|
|
try_files $uri $uri/ /index.php?$args;
|
|
access_log off;
|
|
log_not_found off;
|
|
}
|
|
|
|
location = /xmlrpc.php {
|
|
deny all;
|
|
}
|
|
|
|
# if ($http_user_agent ~* (360Spider|80legs.com|Abonti|AcoonBot|Acunetix|adbeat_bot|AddThis.com|adidxbot|ADmantX|AhrefsBot|AngloINFO|Antelope|Applebot|BaiduSpider|BeetleBot|billigerbot|binlar|bitlybot|BlackWidow|BLP_bbot|BoardReader|Bolt\ 0|BOT\ for\ JCE|Bot\ mailto\:craftbot@yahoo\.com|casper|CazoodleBot|CCBot|checkprivacy|ChinaClaw|chromeframe|Clerkbot|Cliqzbot|clshttp|CommonCrawler|comodo|CPython|crawler4j|Crawlera|CRAZYWEBCRAWLER|Curious|Curl|Custo|CWS_proxy|Default\ Browser\ 0|diavol|DigExt|Digincore|DIIbot|discobot|DISCo|DoCoMo|DotBot|Download\ Demon|DTS.Agent|EasouSpider|eCatch|ecxi|EirGrabber|Elmer|EmailCollector|EmailSiphon|EmailWolf|Exabot|ExaleadCloudView|ExpertSearchSpider|ExpertSearch|Express\ WebPictures|ExtractorPro|extract|EyeNetIE|Ezooms|F2S|FastSeek|feedfinder|FeedlyBot|FHscan|finbot|Flamingo_SearchEngine|FlappyBot|FlashGet|flicky|Flipboard|g00g1e|Genieo|genieo|GetRight|GetWeb\!|GigablastOpenSource|GozaikBot|Go\!Zilla|Go\-Ahead\-Got\-It|GrabNet|grab|Grafula|GrapeshotCrawler|GTB5|GT\:\:WWW|Guzzle|harvest|heritrix|HMView|HomePageBot|HTTP\:\:Lite|HTTrack|HubSpot|ia_archiver|icarus6|IDBot|id\-search|IlseBot|Image\ Stripper|Image\ Sucker|Indigonet|Indy\ Library|integromedb|InterGET|InternetSeer\.com|Internet\ Ninja|IRLbot|ISC\ Systems\ iRc\ Search\ 2\.1|jakarta|Java|JetCar|JobdiggerSpider|JOC\ Web\ Spider|Jooblebot|kanagawa|KINGSpider|kmccrew|larbin|LeechFTP|libwww|Lingewoud|LinkChecker|linkdexbot|LinksCrawler|LinksManager\.com_bot|linkwalker|LinqiaRSSBot|LivelapBot|ltx71|LubbersBot|lwp\-trivial|Mail.RU_Bot|masscan|Mass\ Downloader|maverick|Maxthon$|Mediatoolkitbot|MegaIndex|MegaIndex|megaindex|MFC_Tear_Sample|Microsoft\ URL\ Control|microsoft\.url|MIDown\ tool|miner|Missigua\ Locator|Mister\ PiX|mj12bot|Mozilla.*Indy|Mozilla.*NEWT|MSFrontPage|msnbot|Navroad|NearSite|NetAnts|netEstate|NetSpider|NetZIP|Net\ Vampire|NextGenSearchBot|nutch|Octopus|Offline\ Explorer|Offline\ Navigator|OpenindexSpider|OpenWebSpider|OrangeBot|Owlin|PageGrabber|PagesInventory|panopta|panscient\.com|Papa\ Foto|pavuk|pcBrowser|PECL\:\:HTTP|PeoplePal|Photon|PHPCrawl|planetwork|PleaseCrawl|PNAMAIN.EXE|PodcastPartyBot|prijsbest|proximic|psbot|purebot|pycurl|QuerySeekerSpider|R6_CommentReader|R6_FeedFetcher|RealDownload|ReGet|Riddler|Rippers\ 0|rogerbot|RSSingBot|rv\:1.9.1|RyzeCrawler|SafeSearch|SBIder|Scrapy|Scrapy|Screaming|SeaMonkey$|search.goo.ne.jp|SearchmetricsBot|search_robot|SemrushBot|Semrush|SentiBot|SEOkicks|SeznamBot|ShowyouBot|SightupBot|SISTRIX|sitecheck\.internetseer\.com|siteexplorer.info|SiteSnagger|skygrid|Slackbot|Slurp|SmartDownload|Snoopy|Sogou|Sosospider|spaumbot|Steeler|sucker|SuperBot|Superfeedr|SuperHTTP|SurdotlyBot|Surfbot|tAkeOut|Teleport\ Pro|TinEye-bot|TinEye|Toata\ dragostea\ mea\ pentru\ diavola|Toplistbot|trendictionbot|TurnitinBot|turnit|Twitterbot|URI\:\:Fetch|urllib|Vagabondo|Vagabondo|vikspider|VoidEYE|VoilaBot|WBSearchBot|webalta|WebAuto|WebBandit|WebCollage|WebCopier|WebFetch|WebGo\ IS|WebLeacher|WebReaper|WebSauger|Website\ eXtractor|Website\ Quester|WebStripper|WebWhacker|WebZIP|Web\ Image\ Collector|Web\ Sucker|Wells\ Search\ II|WEP\ Search|WeSEE|Wget|Widow|WinInet|woobot|woopingbot|worldwebheritage.org|Wotbox|WPScan|WWWOFFLE|WWW\-Mechanize|Xaldon\ WebSpider|XoviBot|yacybot|Yahoo|YandexBot|Yandex|YisouSpider|zermelo|Zeus|zh-CN|ZmEu|ZumBot|ZyBorg) ) {
|
|
if ($http_user_agent ~* (SemrushBot|DotBot)) {
|
|
return 444;
|
|
}
|
|
|
|
# Include W3C config if it exists.
|
|
include /var/www/html/nginx[.]conf;
|
|
|
|
# If no favicon exists return a 204 (no content error)
|
|
location ~* /favicon\.ico$
|
|
{
|
|
try_files $uri =204;
|
|
expires max;
|
|
log_not_found off;
|
|
access_log off;
|
|
}
|
|
|
|
# Do not log + cache images, css, js, etc
|
|
location ~* \.(js|css|png|jpg|jpeg|bmp|gif|ico)$ {
|
|
expires max;
|
|
log_not_found off;
|
|
access_log off;
|
|
# Send the all shebang in one fell swoop
|
|
tcp_nodelay off;
|
|
# Set the OS file cache
|
|
open_file_cache off;
|
|
}
|
|
|
|
if (!-e $request_filename) {
|
|
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
|
|
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
|
|
rewrite ^(/[^/]+)?(/.*.php) $2 last;
|
|
}
|
|
|
|
# Deny access to htaccess files
|
|
location ~ /\. {
|
|
deny all;
|
|
}
|
|
|
|
# Deny access to .php files in the /wp-content/ directory (including sub-folders)
|
|
location ~* ^/wp-content/.*.(php|phps)$ {
|
|
deny all;
|
|
}
|
|
|
|
# Deny access to wp-config.php file
|
|
location = /wp-config.php {
|
|
deny all;
|
|
}
|
|
|
|
# Deny access to wp-comments-post.php file
|
|
location = /wp-comments-post.php {
|
|
deny all;
|
|
}
|
|
|
|
# Deny access to readme.html file
|
|
location = /readme.html {
|
|
deny all;
|
|
}
|
|
|
|
# Deny access to license.txt file
|
|
location = /license.txt {
|
|
deny all;
|
|
}
|
|
|
|
# Deny access to specific files in the /wp-content/ directory (including sub-folders)
|
|
location ~* ^/wp-content/.*.(txt|md|exe)$ {
|
|
deny all;
|
|
}
|
|
|
|
###
|
|
# Allow only internal access to .php files inside wp-includes directory
|
|
# location ~* ^/wp-includes/.*\.(php|phps)$ {
|
|
# internal;
|
|
# }
|
|
|
|
# Add trailing slash to */wp-admin requests
|
|
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
|
|
|
|
location ~* /(?:uploads|files)/.*.php$ {
|
|
deny all;
|
|
}
|
|
|
|
###
|
|
# location ~* .(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(.php)?|xtmpl)$|^(..*|Entries.*|Repository|Root|Tag|Template)$|.php_
|
|
# {
|
|
# return 444;
|
|
# }
|
|
|
|
location ~* .(pl|cgi|py|sh|lua)$ {
|
|
return 444;
|
|
}
|
|
|
|
###
|
|
# location ~ /(.|wp-config.php|wp-comments-post.php|readme.html|license.txt) {
|
|
# deny all;
|
|
# }
|
|
|
|
location ~ .(gif|png|jpe?g)$ {
|
|
valid_referers none blocked %%HOSTNAME%%;
|
|
if ($invalid_referer) {
|
|
return 403;
|
|
}
|
|
}
|
|
|
|
location / {
|
|
try_files $uri $uri/ /index.php?$args;
|
|
}
|
|
|
|
##### FASTCGI CACHE #####
|
|
set $nxc_enabled 0;
|
|
set $nxc_skip 1;
|
|
|
|
if (-f "/var/www/html/.enable_nxc") {
|
|
set $nxc_enabled 1;
|
|
# set $nxc_skip 0;
|
|
}
|
|
|
|
if ($nxc_enabled = 1) {
|
|
set $nxc_skip 0;
|
|
}
|
|
|
|
# POST requests and urls with a query string should always go to PHP
|
|
if ($request_method = POST) {
|
|
set $nxc_skip 1;
|
|
}
|
|
|
|
if ($query_string != "") {
|
|
set $nxc_skip 1;
|
|
}
|
|
|
|
# Don't cache uris containing the following segments
|
|
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
|
|
set $nxc_skip 1;
|
|
}
|
|
|
|
# Don't use the cache for logged in users or recent commenters
|
|
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|postpass|wordpress_n$") {
|
|
set $nxc_skip 1;
|
|
}
|
|
########################
|
|
|
|
#####################################################
|
|
# LOCATION: PHP #####################################
|
|
#####################################################
|
|
location ~ \.php$ {
|
|
# proxy_buffers 16 4k;
|
|
# proxy_buffer_size 2k;
|
|
|
|
fastcgi_buffer_size 128k;
|
|
fastcgi_buffers 4 256k;
|
|
fastcgi_busy_buffers_size 256k;
|
|
fastcgi_temp_file_write_size 256k;
|
|
|
|
|
|
#############################################
|
|
# FastCGI Cache #############################
|
|
#############################################
|
|
fastcgi_cache_bypass $nxc_skip;
|
|
fastcgi_no_cache $nxc_skip;
|
|
# fastcgi_no_cache $nxc_exclude;
|
|
fastcgi_cache localhost;
|
|
# fastcgi_cache_valid 60m;
|
|
fastcgi_cache_lock on;
|
|
fastcgi_cache_use_stale updating;
|
|
fastcgi_cache_background_update on;
|
|
fastcgi_cache_valid 200 301 302 60M;
|
|
# fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
|
|
|
|
|
|
if ($nxc_enabled = 1) {
|
|
add_header x-cache-enabled "true";
|
|
}
|
|
|
|
|
|
add_header X-Cache $upstream_cache_status;
|
|
#############################################
|
|
|
|
include fastcgi_params;
|
|
|
|
# fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
|
|
# fastcgi_pass unix:/var/tmp/php-fpm.sock;
|
|
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
|
|
fastcgi_param HTTPS $fcgi_https;
|
|
fastcgi_pass localhost:9000;
|
|
|
|
fastcgi_read_timeout 300;
|
|
}
|
|
|
|
# location ~ /purge(/.*) {
|
|
# fastcgi_cache_purge localhost "$scheme$request_method$host$1";
|
|
# }
|
|
|
|
}
|
|
|