• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question What is the proper nginx additional directives with wordpress

Walter

Basic Pleskian
Here are my additional nginx directives for my websites. It includes caching, compressing, enabling OCSP with Let's Encrypt and certain headers for security. My question is in regards to the settings required for Wordpress to work correctly. The particular setting is:

Code:
#Necessary to enable php fpm for nginx
if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
}

Is the setting above the best way to enable Wordpress with an nginx only and php fpm for nginx 7.1 configuration?
If not, how should I do this?


Code:
#Cache certain web stuff
location ~* \.(png|jpg|ico|js|css|jpeg|gif|woff|woff2|svg)$ {
    expires 8d;
    add_header Pragma public;
    add_header Cache-Control public;
    access_log off;
}
#Gzip site
gzip on;
gzip_disable msie6;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 2;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon text/x-component application/javascript application/rss+xml font/truetype;

#Necessary to enable php fpm for nginx
if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
}

#Enable OCSP
ssl_stapling on;
ssl_stapling_verify on;
#ssl_trusted_certificate /usr/local/psa/var/modules/letsencrypt/etc/live/yourdomain.tld/chain.pem;
resolver 8.8.4.4 8.8.8.8 valid=300s;
resolver_timeout 10s;

#Header Security Additions
server_tokens off;
proxy_hide_header X-Powered-By;
add_header Referrer-Policy no-referrer-when-downgrade;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

add_header Content-Security-Policy "default-src 'none'; script-src 'self' https://www.google-analytics.com/; style-src 'self' https://fonts.googleapis.com; img-src 'self' https://www.google-analytics.com; font-src 'self' https://fonts.googleapis.com https://fonts.gstatic.com; frame-src 'self'; frame-ancestors 'none'; form-action 'none'; upgrade-insecure-requests; block-all-mixed-content; reflected-xss block; base-uri $host www.$host; referrer no-referrer-when-downgrade";

I guess it should be stated that all of this does work well but just want to be sure that the WordPress piece is configured optimally...
 
Last edited:
Back
Top