简体   繁体   中英

Unable to rewrite url in Nginx to login as admin on wordpress

I'm running Wordpress containerized in docker-compose, but for some reason I can't enter http://localhost/wp-admin to login to the dashboard. I get a 404 error from nginx.

This url does work instead: http://localhost/wp/wp-login.php

So I'm trying to rewrite this in nginx, but I get the same 404 response:

    rewrite ^wp-admin$ wp/wp-login.php last;

Why isn't this working?

Full conf:

server {
    listen 80;
    server_name localhost;
    root /var/www/html/web;

    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    # add url to login as admin
    rewrite ^wp-admin$ wp/wp-login.php last;

    # fix slash
    rewrite ^/(.*)/$ /$1 permanent;

    location ~ \.php$ {
        fastcgi_pass php:9000;
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

Try This

Assuming you have a wp-login.php inside /var/www/html/web/wp

  location = /wp-admin {
        rewrite ^/wp-admin?$ /wp/wp-login.php break;
  }

my guess is you're trying to change the WP admin location, this will most likely break the WordPress site. if so Don't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM