Score:0

Nginx reverse proxy + URL rewrite from localhost

be flag
M B

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

Score:1
us flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.