------- Technologies I'm using ---------
- Debian 10
- Nginx server
- PHP8.0
--------- The scenario ------------
I have exmaple.com which has an HTML static website and I have a subdomain, blog.example.com I installed WP on it and it's working fine but I want to make the wp-admin access on login.blog.example.com.
-------- What I tried -------------
1- I tried redirecting any /wp-* URL to login.blog.example.com, but that isn't useful if there are no files/folders of wp-admin on login.blog.example.com.
2- I followed this, but it wasn't handy since they are redirecting to 404 and a static page https://403.ie/how-to-serve-wp-admin-from-a-separate-subdomain/
-------- The nginx configuration -----------
example.com:
server{
listen 80;
listen [::]:80;
server_name IP_ADDRESS;
return 301 http://example.com;
}
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
blog.example.com:
server {
listen 80;
listen [::]:80;
server_name blog.example.com;
root /var/www/blog.example.com;
index index.html index.php index.htm;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location / {
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php$is_args$args;
}
# location /wp-admin{
# rewrite ^/wp-(.*)$ http://login.blog.example.com redirect;
# }
location ~ \.php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}