Answer the question
In order to leave comments, you need to log in
How to set up a reverse proxy on nginx so that the prefix is automatically substituted?
I have 2 services that I want to connect to via a reverse proxy:
https://mydomain.org/service1
https://mydomain.org/service2
If I set proxy_pass to location "/" when logging in, the service returns the .../sign page , which is substituted for the URI. Those. returns https://mydomain.org/sign service opens. If I set location "/service1" and try to log in via https://mydomain.org/service1 , I get to https://mydomain.org/sign - an empty page, while manually typing https://mydomain.org/ service1/sign then the service authorization page will open
how to configure nginx so that the /service1 prefix is substituted by itself
My nginx config
user nginx;
worker_processes auto;
events { worker_connections 1024; }
http {
server {
listen 80 default_server;
server_name mydomain.org;
return 301 https://mydomain.org$request_uri;
}
server {
server_tokens off;
listen 443 ssl;
server_name mydomain.org;
ssl_certificate /etc/nginx/certs/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/privkey.pem;
ssl_prefer_server_ciphers on;
root /usr/share/nginx/html;
include /etc/nginx/mime.types;
proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 8 8k;
location / {
try_files $uri $uri/ /index.html;
}
location /service1 {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://192.168.0.1/;
}
location /service2 {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://192.168.0.2/;
}
gzip on;
gzip_vary on;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_types
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/plain
text/x-component;
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 256;
gunzip on;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question