• mmikolas

    (@mmikolas)


    I switched from shared hosting to my own VPS, from Apache to NGINX. Everything works great, except for one thing. But the permalinks work weird. Actually, I only encounter it within the administration.

    If I delete or copy anything, I am taken from the administration to the home page with my site link, e.g. XX.com/?trashed=1&ids=7998. To confess, I’m a bit desperate and don’t know how to solve this. Here’s a couple of summaries of what I’ve tried.

    nginx configuration – no, nothing to do with that, tested. Configuration file set for WP
    Is the plugin causing this? – no, tested.
    Is it caused by the theme? – no, tested.
    Is it caused by .htaccess? – no, there is none in root anymore.
    Resave or change permalinks? – tested, no result.
    Reinstalling the current version of WP? – didn’t help, no result.

    A completely new installation of WP on my server works great, and I want to avoid having to re-deploy everything manually on my site.

    Where else should I look for the problem? I’m frankly desperate.

    • This topic was modified 10 months ago by mmikolas.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator threadi

    (@threadi)

    The nginx server must have a corresponding rule stored in its own configuration. Similar to the .htaccess of Apache, nginx must know how to handle the URLs. Have you configured anything there?

    Thread Starter mmikolas

    (@mmikolas)

    @threadi I’m sure. As I wrote, NGINX works properly, I tested it on a clean WP instance and I’m using the community recommended configuration.

    NGINX works properly,

    The issue here is the Nginx rewrite rule in your server block, not Nginx per se.

    Just as Apache will work fine but WordPress permalinks will not work unless you add the rewrite rule for Apache, you need to do the same for Nginx.

    Can you share your rewire rule so we take a look?

    Thread Starter mmikolas

    (@mmikolas)

    @gappiah Sure, here is the entire configuration block for my site. I anonymized the site. It wouldn’t make sense that it would be fine for all instances and not for a single instance if it is the same.

    server {
    listen 80;
    listen [::]:80;
    listen 443 quic;
    listen 443 ssl;
    listen [::]:443 quic;
    listen [::]:443 ssl;
    http2 on;
    http3 off;
    {{ssl_certificate_key}}
    {{ssl_certificate}}
    server_name www.example.com;
    return 301 https://example.com$request_uri;
    }

    server {
    listen 80;
    listen [::]:80;
    listen 443 quic;
    listen 443 ssl;
    listen [::]:443 quic;
    listen [::]:443 ssl;
    http2 on;
    http3 off;
    {{ssl_certificate_key}}
    {{ssl_certificate}}
    server_name example.com www1.example.com;
    {{root}}

    {{nginx_access_log}}
    {{nginx_error_log}}

    if ($scheme != "https") {
    rewrite ^ https://$host$request_uri permanent;
    }

    location ~ /.well-known {
    auth_basic off;
    allow all;
    }

    {{settings}}

    location ~/\.git {
    deny all;
    }

    location = /xmlrpc.php {
    deny all;
    }

    location ~/(wp-admin/|wp-login.php) {
    #auth_basic "Restricted Area";
    #auth_basic_user_file /home/site-user/.htpasswd;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:2040;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout 7200;
    proxy_send_timeout 7200;
    proxy_read_timeout 7200;
    proxy_buffer_size 128k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
    }

    location / {
    {{varnish_proxy_pass}}
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_hide_header X-Varnish;
    proxy_redirect off;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout 720;
    proxy_send_timeout 720;
    proxy_read_timeout 720;
    proxy_buffer_size 128k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
    }

    location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf|map)$ {
    # WordPress Multisite Subdirectory
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 break;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 break;
    add_header Access-Control-Allow-Origin "*";
    add_header alt-svc 'h3=":443"; ma=86400';
    expires max;
    access_log off;
    }


    if (-f $request_filename) {
    break;
    }
    }

    server {
    listen 8080;
    listen [::]:8080;
    server_name example.com www1.example.com;
    {{root}}

    include /etc/nginx/global_settings;

    try_files $uri $uri/ /index.php?$args;
    index index.php index.html;

    location ~ \.php$ {
    include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    try_files $uri =404;
    fastcgi_read_timeout 3600;
    fastcgi_send_timeout 3600;
    fastcgi_param HTTPS "on";
    fastcgi_param SERVER_PORT 443;
    fastcgi_pass 127.0.0.1:{{php_fpm_port}};
    fastcgi_param PHP_VALUE "{{php_settings}}";
    }

    # WordPress Multisite Subdirectory
    if (!-e $request_filename) {
    rewrite /wp-admin$ https://$host$uri permanent;
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
    }

    if (-f $request_filename) {
    break;
    }
    }
    Mehmet ARIK

    (@mehmetarik)

    “A completely new installation of WP on my server works great, and I want to avoid having to re-deploy everything manually on my site.”

    It seems you didn’t install Nginx as standalone server. It works with Apache as a reverse proxy.

    try_files $uri $uri/ /index.php?$args;
      index index.php index.html;

    This line indicates permalinks. It seems true. Did you tried reload Nginx conf ?
    nginx -s reload
    add this end of the Nginx conf file. And try again if it works.

    Thread Starter mmikolas

    (@mmikolas)

    @mehmetarik

    No, my server only runs nginx, including X dozens of WP instances and custom applications. Please stick to what I wrote in the original post.

    Of course we tried reloading nginx. As I stated, all WP instances running on my server are working without this problem. The problem only occurred with this site because there was a migration from a hosted solution with apache. 🙁

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Permalinks don’t work after switching from Apache to NGINX’ is closed to new replies.