Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

332
Visualizações
Variable in nginx proxy_pass causes MIME type issue

I've googled the topic at length all evening and can't seem to make sense of this. My situation is the following: I have a NAS on my network (hostname MYHOSTNAME) and I also have a nginx reverse proxy, on another machine. I want to use a variable for the proxy_pass section of my configuration file such that in case the NAS is offline when the proxy starts, it doesn't crash. Basically:

location /MYNAS {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_redirect   off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://MYHOSTNAME:1234/; 

works just fine. But the following:

location /MYNAS {
        set $VAR_HOSTNAME MYHOSTNAME;
        resolver 192.168.x.x;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_redirect   off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://$VAR_HOSTNAME:1234/;

gives me trouble. The webpage loads an empty page, and in the browser console, I can see:

Refused to execute script from 'something' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
mydynamicdns/:1 Refused to execute script from 'somethingelse' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
desktop.js?v=1562143318:3 Uncaught TypeError: Cannot read property 'diskless' of undefined
    at _S (desktop.js?v=xxx:x)
    at aa.defaultCSSSelectors (desktop.js?v=xxx:x)
    at desktop.js?v=xxx:x
    at ext-all.js?v=xxx:x
    at b (ext-all.js?v=xxx:x)

I'm at a loss for new ideas of how to make this work... Thanks in advance guys, any help would be greatly appreciated.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I don't think I can quite explain the technical details of why, but by turning on debugging in nginx and comparing with the usecase that works, I eventually figured that I needed to nullify the /MYNAS/ piece. The key is the rewrite line below:

location /MY_NAS/ {
        set $MY_NAS http://MYNAS:1234;
        resolver 192.168.x.x;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_redirect   off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        rewrite /MY_NAS/(.*) /$1 break;
        proxy_pass $MY_NAS;
    }

Hopefully that will help someone else one day and save you the headache.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda