简体   繁体   English

通过/ admin URL访问Wordpress WP-Admin

[英]Access Wordpress WP-Admin through /admin URL

I want to access to my /wp-admin through a different URL, such as /admin . 我想通过其他URL(例如/admin访问我的/wp-admin /admin

If I do localhost:5000/admin I got redirected to localhost:8000/wp-admin , the requirement is that I should see the Wordpress administration panel at that exact URL. 如果执行localhost:5000/admin则将我重定向到localhost:8000/wp-admin ,要求是我应该在该确切的URL上查看Wordpress管理面板。

I'm using docker-compose and nginx . 我正在使用docker-composenginx

My nginx.conf file looks like: 我的nginx.conf文件如下所示:

events { worker_connections 1024; }
http{
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  server {
    listen 80;
    listen [::]:80;

    server_name localhost;

    location ~* /admin {
        rewrite ^/admin/(.*) /wp-admin last;
        proxy_pass http://wordpress;
        proxy_set_header Access-Control-Allow-Origin *;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;


    }
  }

}

And my docker-compose.yml file is: 我的docker-compose.yml文件是:

version: '2'
services:
  db:
    image: mysql:5.6
    restart: unless-stopped
    volumes:
      - ./backend/db/db_data:/var/lib/mysql
      - ./backend/db/init.sql:/docker-entrypoint-initdb.d/init.sql
    environment: 
      MYSQL_ROOT_USER: root
      MYSQL_ROOT_PASSWORD: p4ssw0rd!
      MYSQL_DATABASE: wordpress

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: unless-stopped
    ports:
      - 8081:80
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: p4ssw0rd!



  wordpress:
    depends_on:
      - phpmyadmin
      - db
    image: wordpress
    restart: unless-stopped
    volumes:
      - ./backend/wordpress/wp-content:/var/www/html/wp-content
      - ./backend/wordpress/.htaccess:/var/www/html/.htaccess
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_PASSWORD: p4ssw0rd!
      WORDPRESS_TABLE_PREFIX: ab_
      WORDPRESS_CONFIG_EXTRA:
        define('JWT_AUTH_SECRET_KEY', 'secret');
        define('JWT_AUTH_CORS_ENABLE', true);
        define('WP_ALLOW_REPAIR', true );
    ports:
      - 8000:80 # Expose http and https
      - 8001:443

  nginx:
    build: ./backend/nginx
    volumes:
      - ./backend/nginx/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - "5000:80"
    links: 
      - wordpress
      - frontend
    depends_on: 
      - wordpress
      - frontend

Not an nginx expert so any help is appreciated. 不是nginx专家,因此不胜感激。

Try using this filter too 也尝试使用此过滤器

function custom_admin_url($path) { 
    return str_replace('wp-admin', 'admin', $path); 
}
add_filter('admin_url', 'custom_admin_url');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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