Last active
July 15, 2022 20:57
-
-
Save denvers/071ea7302f133f71f252 to your computer and use it in GitHub Desktop.
Nginx directives for use in ISPConfig - Nginx PHP7 FPM
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
# Force non-www to www redirect | |
if ($host !~* ^www\.) { | |
rewrite ^(.*)$ $scheme://www.$host$1 permanent; | |
} | |
# Turn on SSL | |
# protip: https://mozilla.github.io/server-side-tls/ssl-config-generator/ | |
ssl on; | |
add_header Strict-Transport-Security max-age=15768000; | |
# General configs | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
# WordPress single site rules. | |
# Designed to be included in any server {} block. | |
# This order might seem weird - this is attempted to match last if rules below fail. | |
# http://wiki.nginx.org/HttpCoreModule | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
# Add trailing slash to */wp-admin requests. | |
rewrite /wp-admin$ $scheme://$host$uri/ permanent; | |
# Directives to send expires headers and turn off 404 error logging. | |
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|css|js)$ { | |
access_log off; log_not_found off; expires max; | |
} | |
# Uncomment one of the lines below for the appropriate caching plugin (if used). | |
#include global/wordpress-wp-super-cache.conf; | |
#include global/wordpress-w3-total-cache.conf; | |
# Pass all .php files onto a php-fpm/php-fcgi server. | |
location ~ [^/]\.php(/|$) { | |
fastcgi_split_path_info ^(.+?\.php)(/.*)$; | |
if (!-f $document_root$fastcgi_script_name) { | |
return 404; | |
} | |
# This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default) | |
include fastcgi.conf; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_pass php; | |
} |
In /etc/nginx/sites-available/domain.com.vhost:
root /var/www/domain.com/web/public;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how would I change this directive snippet if my wordpress site was in a subfolder for exampe
{DOCROOT}/public