Score:0

NginX redirect Frontend to different port and path

tn flag

For some very specific reasons I have to access two different routes on my frontend and the only variable in how they are accessed I have control over is the port. So what I would like to do is depending on the port, either access the frontent normally, or access it under a different path:

myUrl:80 -> myUrl:80
myUrl:8081 -> myUrl:80/someRoute

I have tried to implement this with a proxy_pass as follows:

# Standard frontend server
server {
    listen 80 default_server;
    server_name _;

    root /usr/share/nginx/html;
    index index.html;
    error_page 500 502 503 504 /50x.html;

    location / {
        try_files $uri $uri/ /index.html
        add_header Cache-Control "no-cache";
    }

    location /static {
        expires 1y;
        add_header Cache-Control "public";
    }
}

# Proxy $url:8081 -> url:80/somePath/
server {
    listen 8081 default_server;
    server_name _;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Original-Host $http_host;
        proxy_set_header X-Original-Scheme $scheme;
        proxy_set_header X-Forwarded-For $remote_addr;

        proxy_pass http://127.0.0.1:80/somePath/;
    }

}

This then throws an error in the frontend console:

The script has an unsupported MIME type ('text/html').

In case it's relevant, I'm using Flutter Web.

masus04 avatar
tn flag
To clarify: for api routes, the proxying works fine, it's just when I access the frontend with a browser that some things don't work 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.