Score:0

Unable to access Wordpress Dashboard with nginx reverse proxy

sd flag

I am facing a bit of an issue when setting up WordPress with Nginx as reverse proxy to Apache backend. All the pages are loading, but i get an error when i try to login to wp-admin dashboard. The error is Sorry, you are not allowed to access this page.

I have checked my file permissions, database prefix,.htaccess and even usermeta admin privileges in the db, all seem to be perfect. The site was working perfectly fine before i setup nginx reverse proxy.

Here is my apache2 config:

   <VirtualHost *:8081>
       DocumentRoot "/mnt/NAS/wp_data/wordpress/"
       ServerName my_site_url
       ServerAlias www.my_site_url
    
    <Directory "/mnt/NAS/wp_data/wordpress/">
       Options MultiViews FollowSymlinks
       AllowOverride All
       Order allow,deny
       Allow from all
    </Directory>
    
   </VirtualHost>

Here is my apache ports.conf:

   #Listen 80
   Listen 8081

Here is my nginx config:

server {
        listen 80;
        listen [::]:80;

        server_name my_site_url;

        rewrite ^ https://$server_name$request_uri? permanent;

}

server {
        listen 443 ssl;
        listen [::]:443 ssl;

        server_name www.my_site_url my_site_url;

        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_pass http://127.0.0.1:8081;
        }

        ssl_certificate /var/www/mycert/certificate.pem;
        ssl_certificate_key /var/www/mycert/private.key;
}

Last but not least my wp-config.php is as default and i haven't added anything else apart from

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
if ( 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
$_SERVER['HTTPS'] = 'on';
}
}
if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
}
Mrwut avatar
ng flag
Is it working without the ssl? Also try to put `define('FORCE_SSL_ADMIN', true);` At the beginning of the config file and see if that helps.
sd flag
I tried adding it, didn't make a difference. Btw, i use a custom folder where i have my wordpress directory as shown above. I dont use /var/www/ or /var/www/html, i use /mnt/NAS/wp_data/wordpress directorty. I have added this to apache.conf and also i've chowned it to www-data:www-data. Technically that shouldn't be an issue. I am unable to login to wp-admin area. It says you are not allowed to access this. I am however able to use the same folder and same files by removing nginx proxy and just using plain apache as before. Any more guidance will be highly appreciated. Thanks!
Mrwut avatar
ng flag
I've meant to add it to the wp-config.php. If you've added there and the result is still the same, you could try to search for a line like `define('DISALLOW_FILE_MODS',true);` in the wp-config.php, and if it's there you can try to delete it and see if it helps.
sd flag
No luck. Should i just try to use nginx alone for wp instead of the reverse proxy? If so could you please provide me with a sample config with ssl to refer from?
Score:0
me flag

I was able run Wordpress and its dashboard on apache with nginx as reverse proxy

the nginx configuration is

 location ^~ /blog/ {
    proxy_pass http://x.y.x.z/;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

and in the wp-config.php (on apache server) the following contents are added

$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/",  $_SERVER['REQUEST_URI']);


if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
if ( 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
$_SERVER['HTTPS'] = 'on';
}
}
if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.