A
A
Alexander2016-07-04 12:52:47
Nginx
Alexander, 2016-07-04 12:52:47

How to set up NGINX for Wordpress CNC?

Hello, please help me to make .htaccess work on Nginx + Php-fpm
There is a site on Wordpress, I use the latest version of VestaCP as a panel.
Previously, all I had to do was select the WebNGINX "wordpress2" template for the domain. After installing the latest version (16), all internal links with this template do not work. The main one loads properly, but the internal ones give out 404.
I found this instruction ( goo.gl/uik5eU):

"try_files $uri $uri/ /index.php?$args;" /home/мой пользователь/conf/web/.

"try_files $uri $uri/ /index.php?$args;" Needs to be added to the location section of each website you host.

Tried editing wordpress2 template located at
/usr/local/vesta/data/templates/web/nginx/php-fpm/wordpress2.tpl
/usr/local/vesta/data/templates/web/nginx/php-fpm/wordpress2 .stpl
But there is already this code in the first location section. I will give the full config of the wordpress2 template:
server {
    listen      %ip%:%web_port%;
    server_name %domain_idn% %alias_idn%;
    root        %docroot%;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/%domain%.log combined;
    access_log  /var/log/nginx/domains/%domain%.bytes bytes;
    error_log   /var/log/nginx/domains/%domain%.error.log error;

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

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

    location / {
    try_files $uri $uri/ /index.php?$args;

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    %backend_lsnr%;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     %home%/%user%/conf/web/nginx.%domain%.conf*;
}

services restarted
service nginx restart
service php-fpm restart (just in case)
If you select the WebNGINX "wordpress" Template, then the internal ones do not issue more than 404, but simply show the content of the main one. Good people, please help to get the CNC working on Nginx for Wordpress as soon as possible. Before updating VestaCP to version 16, everything with templates worked with a bang ...
I'm waiting for your opinions, solutions, what I'm doing wrong and recommendations
PS
Freshly installed wordpress-4.5.2-ru_RU behaves similarly on the WebNGINX "wordpress2" template - it gives 404, on the "wordpress" template shows the main page

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Vorotnev, 2016-07-04
@inwebwetrust

All that is needed for CNC in WordPres + Nginx is:
1. try_files $uri $uri/ /index.php?$args;in the config
2. Resave permalinks (WordPress admin - Settings - Permalinks)
If it doesn't work, the problem is elsewhere. We need to look at the logs, start with Nginx access.log and error.log

N
nikolayvaganov, 2016-07-04
@nikolayvaganov

In root location:

if (!-e $request_filename ) { rewrite ^(.*)$ /index.php?q=$1; }

A
Anton Kulyavets, 2017-02-04
@SPEC1AL1ST

Hello, I decided to switch from Apache to php-fpm and ran into a problem, please help.
I have my code in .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Translated to nginx as
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}

I insert instead
location / {

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    127.0.0.1:9004;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

But for some reason it doesn't work. Who can help with the correct code or am I doing something wrong?
The codes above don't work or I put them in the wrong way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question