![Zugriff auf Wordpress-Dashboard mit Nginx-Reverse-Proxy nicht möglich](https://rvso.com/image/776285/Zugriff%20auf%20Wordpress-Dashboard%20mit%20Nginx-Reverse-Proxy%20nicht%20m%C3%B6glich.png)
Ich habe ein kleines Problem beim Einrichten von WordPress mit Nginx als Reverse-Proxy für das Apache-Backend. Alle Seiten werden geladen, aber ich erhalte eine Fehlermeldung, wenn ich versuche, mich beim wp-admin-Dashboard anzumelden. Der Fehler istSorry, you are not allowed to access this page.
Ich habe meine Dateiberechtigungen, das Datenbankpräfix, .htaccess und sogar die Usermeta-Administratorrechte in der Datenbank überprüft, alles scheint perfekt zu sein. Die Site funktionierte einwandfrei, bevor ich den Nginx-Reverse-Proxy eingerichtet habe.
Hier ist meinApache2-Konfiguration:
<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>
Hier ist meinapache ports.conf:
#Listen 80
Listen 8081
Hier ist meinNginx-Konfiguration:
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;
}
Zu guter Letzt meinewp-config.phpist als Standard und ich habe nichts anderes hinzugefügt außer
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'];
}
Antwort1
Ich konnte Wordpress und sein Dashboard auf Apache mit Nginx als Reverse-Proxy ausführen
die nginx-Konfiguration ist
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;
}
und in der wp-config.php (auf dem Apache-Server) werden folgende Inhalte hinzugefügt
$_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'];
}