By nickeyvee
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 {
server 127.0.0.1:8080;
}
# 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/;
}
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Looks like Stack Overflow might have the answer!
https://serverfault.com/questions/627305/hide-port-in-nginx-reverse-proxy-redirection/628992
I would first try adding these two options to your nginx.conf:
server_name_in_redirect off;
proxy_set_header Host $host:$server_port;
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.