Nginx WordPress config file
19:30 | 0 comments

This file is suitable with PHP-FPM and Nginx.

First , create a new configuration file for Nginx and put it in sites-available directory of your Nginx . Its usually in /etc/nginx/sites-available/ directory.

File name must ends with .conf

Then copy and paste below code into your file and save it with the suitable name .


server {
        ## Your website name goes here.
        server_name sepehrsoltani.ir;
        ## Your only path reference.
        root /var/www/sepehrblog;
        ## This should be in your http block and if it is, it's not needed here.
        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}
         

Dont forger to restart your Nginx.

Sudo systemctl restart nginx 

COMMENTS

Post your comment

Your email address will not be published. Required fields are marked *