Strahinja90bg
Strahinja90bg

Reputation: 161

Whats the correct way to write nginx configuration for wordpress?

I have a problem with configuring my wordpress nginx settings. This is my nginx configuraton

server {
        listen                  80;
        server_name             wordpress.project;
        access_log              /var/log/nginx/wordpress.project/access.log;
        error_log               /var/log/nginx/wordpress.project/error.log;
        root                    /var/www/wordpress.project;

        location / {
                index app_dev.php;
                if (-f $request_filename) {
                break;
                }
                rewrite ^(.*)$ /app_dev.php last;
        }

        location ~ \.php$ {
                fastcgi_split_path_info         ^(.+\.php)(.*)$;
                fastcgi_pass                    unix:/var/run/php5-fpm.sock;
                #fastcgi_pass                    127.0.0.1:9000;
                fastcgi_index                   index.php;
                fastcgi_param                   SCRIPT_FILENAME  $request_filename;
                include                         fastcgi_params;

        }

}

Hosts file is set as 127.0.0.1 wordpress.project

Permissions of folders are set

sudo chmod -R a+rw /var/www/wordpress.project
sudo chown -R www-data:www-data /var/www/wordpress.project

And symbolic link is set

sudo ln -s /etc/nginx/sites-available/wordpess.project /etc/nginx/sites-enabled/wordpess.project

And there is still an error when i try accessing wordpress.project saying

File not found

Project has classic wordpress structure of files enter image description here Is this correct configuration for wordpress in nginx and if its not what is the best way?

Upvotes: 1

Views: 182

Answers (1)

Vishnu Gp
Vishnu Gp

Reputation: 5

Try this

server
{
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/wordpress.project;
        index index.php index.html index.htm;

        server_name your_domain.com;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

Please restart Nginx after changing the configuration (sudo service nginx restart)

Upvotes: 1

Related Questions