Using WordPress with Apache behind an nginx reverse proxy

I hope you can help me solving my issue.

I am running ngninx on a dedicated Server as a reverse proxy. My WordPress Application is on another VM, which is running apache2 as a Websever. Everything is working fine until I use “permalinks” in WordPress. I am receiving:

“The requested URL /contact-us/ was not found on this server.”

Here is my config on nginx:

server {
        listen          443;
        ssl         on;
        server_name     foo.com;


        access_log  /var/log/nginx/foo.access.log;
        error_log   /var/log/nginx/foo.error.log;


        ssl_certificate           /etc/nginx/ssl-certificates/foo.de.crt;
        ssl_certificate_key       /etc/nginx/ssl-certificates/foo.de.key;


        ssl_protocols        SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers RC4:HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
        keepalive_timeout    60;
        ssl_session_cache    shared:SSL:10m;
        ssl_session_timeout  10m;

        location / {
            proxy_pass  https://111.111.111.111;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }

}
server {
    listen      80;
    server_name     foo.com;

    add_header Strict-Transport-Security max-age=2592000;
    rewrite ^/.*$ https://$host$request_uri? permanent;
}

I don’t know the reason why I can’t use permalinks. Anyone facing the same Problem?

Thanks in Advanced!

1 Answer
1

You’re missing your WordPress rewrite rules.

It’s probably confusing because, in Apache, WordPresss automatically generates the rewrite rules in .htaccess. It does not do the same in nginx environments.

Pay special attention to the WordPress documentation on nginx and configuration directives referencing HTTP rewrite rules, the “includes” directives for segmenting configuration and the specific WordPress rewrite rules that need to be present for pretty permalinks to work properly.

Without knowing a lot about your operating system, site/network or setup, I hesitate to copy and paste code without context. This section of the documentation is pretty thorough, and should provide what you’re looking for.

Leave a Comment