nginx proxy reveals /wp-admin and /wp-login backend url and port number

I am currently trying to use Nginx as a reverse proxy and as my back-end file server in place of Apache. The goal is to only use the worpress-api as a backend service for my Express.js website.

When passing requests using /admin and /login the backend server path and port number is revealed.

Expected behavior:

http://domain_name/admin ===> http://domain_name/admin http://domain_name/login ===> http://domain_name/login Actual Behavior:

http://domain_name/admin ===> http://domain_name:8080/wp-admin/ http://domain_name/login ===> http://domain_name:8080/wp-login/

Here is my Nginx default config:

upstream file_server {

# file-server block
server {
    listen 8080;
    server_name localhost;
    root /var/www/headless-cms/admin;
    index index.php index.html index.htm index.nginx-debian.html;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;

    location ~ /\.ht {
        deny all;

# proxy server block
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name domain_name;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    location / {
       # settings for express.js server
       # proxy_pass http://localhost:5000/;
       try_files $uri $uri/ =404;

    location /api {
        proxy_pass http://file_server/wp-json/;

    location /login {
        proxy_pass http://file_server/wp-login.php;

    location /admin {
        proxy_pass http://file_server/wp-admin/;


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Looks like Stack Overflow might have the answer!

I would first try adding these two options to your nginx.conf:

server_name_in_redirect off;
proxy_set_header Host $host:$server_port;