0

I would like to rewrite the URL in a reverse proxy so in my case I would like to change url like below, I ran some containers so they callable now but with port and localhost I add a new container with nginx revers proxy and with this I would like to revert my url but I don't know how should I define nginx.conf in this path /etc/nginx/nginx.conf:

when I enter some url it should call like below: http://addons.example.com => http://localhost:89 http://my.example.com => http://localhost http://phpmyadmin.example.com => http://localhost:5054 

due to my config I got this error in docker log when I call http://addons.project.com/test.php: production_nginx | 2022/02/23 13:49:27 [error] 31#31: *1 open() "/etc/nginx/html/test.php" failed (2: No such file or directory), client: 172.25.0.1, server: my.project.com, request: "GET /test.php HTTP/1.1", host: "addons.project.com"

this is my config of nginx:

events { } http { client_max_body_size 20m; proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m; server { server_name my.example.com; location /my.example.com/ { proxy_pass http://127.0.0.1:80; rewrite ^/my.example.com(.*)$ $1; } location /addons.example.com/ { proxy_pass http://127.0.0.1:89; rewrite ^/addons.example.com(.*)$ $1; } } } 

Thanks in advance

1 Answer 1

1

You are looking for virtual host setups, not location blocks in a single server block.

Your current setup corresponds to following URLs:

https://my.example.com/my.example.com -> 127.0.0.1:80 https://my.example.com/addons.example.com -> 127.0.0.1:89 

You likely want separate server blocks:

server { server_name my.example.com; proxy_pass http://localhost; } server { server_name addons.example.com; proxy_pass http://localhost:89; } server { server_name phpmyadmin.example.com; proxy_pass http://localhost:5054; } 

You might need the rewrite statements if you cannot configure your applications base URL properly.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.