Created
June 19, 2024 03:46
-
-
Save alucard001/352a376e8d78476fde086e73b56ab9f5 to your computer and use it in GitHub Desktop.
Wordpress Multisite with subdirectory setup - nginx conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For wordpress multisite networks with sub-directory installs | |
# nginx.conf | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name example.com; | |
index index.php index.html index.htm; | |
proxy_buffer_size 256k; | |
proxy_buffers 4 512k; | |
proxy_busy_buffers_size 512k; | |
proxy_max_temp_file_size 0; | |
proxy_read_timeout 600; | |
proxy_connect_timeout 600; | |
proxy_send_timeout 600; | |
root /var/www/html-example; | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
location ~* /xmlrpc.php { | |
deny all; | |
return 404; | |
} | |
rewrite_log on; | |
location ~* ^/sub_dir/ { | |
try_files $uri $uri/ /sub_dir/index.php$is_args$args; | |
if (!-e $request_filename) { | |
rewrite /sub_dir/wp-admin$ $scheme://$host$uri/ permanent; | |
rewrite /sub_dir(/[^/]+)?(/wp-.*) /sub_dir/$2 last; | |
rewrite /sub_dir(/[^/]+)?(/.*\.php)$ /sub_dir$2 last; | |
rewrite /sub_dir(/[^/]+)?(/[^/]+)?(/.*\.php)$ /sub_dir$2 last; | |
rewrite /sub_dir(/[^/]+)? /sub_dir/ last; | |
} | |
location ~ ^/sub_dir(/[^/]+)(/wp-.*\.php) { | |
rewrite /sub_dir(/[^/]+)?(/wp-.*\.php)$ /sub_dir$2 last; | |
} | |
location ~ \.php { | |
include fastcgi_params; | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_index index.php; | |
fastcgi_hide_header X-Powered-By; | |
fastcgi_param SCRIPT_FILENAME /var/www/html-example/$fastcgi_script_name; | |
fastcgi_param PATH_INFO $fastcgi_path_info; | |
} | |
} | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location ~* \.(?:ico|css|js|gif|jpe?g|png|svg|swf|ico|pdf|mov|fla|zip|rar)$ { | |
expires max; | |
log_not_found off; | |
add_header Pragma public; | |
add_header Cache-Control "public"; | |
} | |
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). | |
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) | |
location ~ /\. { deny all; } | |
# Deny access to any files with a .php extension in the uploads directory | |
# Works in sub-directory installs and also in multisite network | |
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) | |
location ~* /(?:uploads|files)/.*\.php$ { deny all; } | |
location ~ \.php$ { | |
fastcgi_read_timeout 600; | |
fastcgi_send_timeout 600; | |
include fastcgi_params; | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_index index.php; | |
fastcgi_hide_header X-Powered-By; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_intercept_errors on; | |
fastcgi_param PATH_INFO $fastcgi_path_info; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment