GutenTag and thanks in advance for the help.
I am trying to use a subfolder reverse proxy, in this case to an instance of Frigate on http://192.168.1.10:5000 using http://www.example.com/frigate
I have the location block set up and it is forwarding, however the urls aren't all getting forwarded properly. So for example, in the Frigate code:
<script type="module" crossorigin src="/assets/index.e8c171d2.js"></script>
<link rel="modulepreload" href="/assets/vendor.153a2319.js">
<link rel="stylesheet" href="/assets/index.876b5b15.css">
"/assets/index.e8c171d2.js" should be forwarding to http://www.example.com/frigate/assets/index.e8c171d2.js, however it's coming across as http://www.example.com/assets/index.e8c171d2.js, which doesn't exist.
How can I rewrite the urls in so that any links/references add the "/frigate" in front?
Here's the location block I have right now:
location ^~ /frigate/ {
include /config/nginx/proxy.conf;
include /config/nginx/resolver.conf;
set $upstream_app 192.168.1.10;
set $upstream_port 5000;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
rewrite /frigate(.*) $1 break;
proxy_hide_header X-Frame-Options;
}
Obviously the rewrite line I have is not covering everything.
Thanks again!
Seth
Related
I am quite new to NGINX and within this topic it is still very hard for me to find the right buzzwords to have more successful search results. That is why I try to descibe my problem here and maybe some of you can point me in the right direction. For my own personal project I want to set up a website which is composed from several micro services (which have all their own frontend).
My idea was to have one NGINX sever running serving as web server to deliver some kind of HTML which then includes the content of the micro services via server side includes (SSI).
Since the SSI can only include files and local folders as I understand I added some proxy_pass to my local server configuration:
http {
server {
listen 80;
ssi on;
root /usr/share/nginx/html;
location /led-todo {
proxy_pass http://led-todo-frontend:3000/;
}
}
}
So since I have the NGINX and my micro services in the same docker-compose running the URL: http://led-todo-frontend:3000 works.
The issue I am facing now is that when access my index.html page:
<html>
<head>
</head>
<body>
<!--# include virtual="test.html"-->
<!--# include virtual="/led-todo/"-->
</body>
</html>
The index.html content of my micro service is actually included into the above shown html site.
The issue arises when the script tags within my included html content are resolved:
<script src="/static/js/bundle.js">
The browser tries to load them from:
http://localhost:8080/static/js/bundle.js
Instead of:
http://localhost:8080/led-todo/static/js/bundle.js
Which then would again trigger the proxy pass to the correct micro service.
I feel like there should be some parameters to define the root or something so that /static/js/bundle.js is not loaded from localhost:8080 but from localhost:8080/led-todo in the following part of the NGINX configuration:
location /led-todo {
proxy_pass http://led-todo-frontend:3000/;
}
I tried several things I found in the internet here but somehow I am missing the words to describe this issue so that I can find results...
Anyone know how to solve this issue, or know at least some buzzwords I can search for?
This isn't a very elegant solution, but you can try to on-the-fly rewriting that tags content with the ngx_http_sub_module, something like this could work:
location /led-todo/ {
proxy_pass http://led-todo-frontend:3000/;
sub_filter_once off;
# uncomment to do substitution inside CCS or JS content too
# sub_filter_types text/css application/javascript;
sub_filter 'href="/' 'href="/led-todo/';
sub_filter "href='/" "href='/led-todo/";
sub_filter 'src="/' 'src="/led-todo/';
sub_filter "src='/" "src='/led-todo/";
}
I'm configuring nginx to load only static files and I don't know why .css files are interpreted as text/plain - finally browser couldn't load it.
Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://localhost:13000/styles.css".
when I check response header in web browser of css file:
Content-Type: text/plain
I know that on stack we have a lot of issues with it, I've already read them but still doesn't work.
in html file I've just import css:
<link href="styles.css" rel="stylesheet" type="text/css"/>
my /etc/nginx/nginx.conf is:
worker_processes 1;
events {
worker_connections 512;
}
http {
server {
listen 80;
server_name 0.0.0.0:80;
include /etc/nginx/mime.types;
root /project/app;
location ~* ^.+\.(js|css)$ {
expires 10d;
}
}
}
I tried without any location part or tried with:
location ~ \.css {
add_header Content-Type text/css;
}
In some responses in other threads I saw that this part is required:
default_type application/octet-stream;
include /etc/nginx/mime.types;
I added it in http part and after that in server and then in location, still didn't help me.
Is there anything else what can I do to fix it?
Just in case somebody has the same problem and use docker.
This is key word - I use docker with image nginx:latest which causes problems, I've changed it to nginx:1.14.2 and everything is working fine.
in html, import css:
<link href="styles/styles.css" rel="stylesheet" type="text/css"/>
my nginx.conf configuration:
worker_processes 1;
events {
worker_connections 512;
}
http {
include mime.types;
sendfile on;
server {
listen 80;
server_name 0.0.0.0:80;
root /project/app;
}
}
I solved the issue for myself. The problem on my side was the actual nginx configuration, let me explain.
Not working (before):
my dockerfile contained this line of code: "COPY deployment/nginx.conf /etc/nginx/nginx.conf"
my nginx.conf contained the "http {" part
How I fixed it:
I updated my docker file to: "COPY deployment/nginx.conf /etc/nginx/conf.d/default.conf" (check the new path where I am copying)
my nginx.conf did not contain any more "http {" block and just the "server {" block. (This works because I am adding a new config file).
Voila! Hope it helps! All in all the culprit was where I was copying the config file and the content of my conf file itself.
I had a similar issue once on my testing server. what i found out was that nginx was doing every thing in the right way. The problem was the referencing of the files. The browser could find the resources but could not load them from the described base.
location / { # default base
root /var/www/html/myfiles; # my root folder
try_files $uri /index.html;
include /etc/nginx/mime.types;
}
changed the base to...
location /myfiles { # changed base
root /var/www/html; # default root folder
try_files $uri /index.html;
include /etc/nginx/mime.types;
}
it worked seamlessly
I had this problem.
In order to solve it for both my static javascript and css files was to add type AND uic-remove as followed:
<link rel="stylesheet" uic-remove href="/index.css" type="text/css">
<script uic-remove type="application/javascript" src="./index.js"></script>
Note: The Javascript link was not throwing any warning or error like the css's warning, however it was nonetheless not working either and I thank the heavens that the fix worked for both. Good Luck!
When visiting /abc/sitemap.xml I'd like to display the content of /abc/sitemap?output=xml without changing the url.
Currently, it shows the right content, but changes the url to /abc/sitemap?output=xml instead of keeping /abc/sitemap.xml, and here is my config.
location /abc/sitemap.xml {
rewrite ^ /abc/sitemap?output=xml;
}
Thanks
How about a proxy_pass:
location /abc/sitemap.xml {
proxy_pass http://$host/abc/sitemap?output=xml;
}
Note: use HTTP or HTTPS depending on your SSL configurations.
I have a nginx (:80) and an upstream server (:8080) running on my machine.
I want to proxy all requests to /assets/(*.?) to upstream's /upstream/$1 location.
The upstream server redirects (302) /upstream/file_id to the /real/file/location.ext
Here is my code:
location /assets/ {
rewrite ^/assets/(.*) /upstream/$1 break;
proxy_pass http://127.0.0.1:8000;
}
This seems to work, but on the client side I get the redirected location:
http://myserver.com/real/file/location.ext
I kinda want to hide it so that it stays:
http://myserver.com/assets/file_id
The idea behind this is to make the upstream server find the real file's location, but let the nginx serve the file without giving away its real location. Is this even possible?
first you're using 8000 in proxy_pass, but you're mentioning your port is 8080.
Second, remove the rewrite line should do the trick, because youre actually using the rewrite rule here and never get to the proxy_pass line. Something like the following should work:
location /assets/ {
include proxy_params;
proxy_pass http://127.0.0.1:8080;
}
There are also proxy_rewrite and proxy_redirect commands which might help you in getting this upstream-redirect handled internally by nginx.
Hope that helps!
we have two servers, A and B. Server A is accessed worldwide. He has nginx installed. That's what I have in conf:
location /test {
proxy_pass http://localserver.com;
}
What it should do, is translate the addreess http://globalserver.com/test (that is server A) to internal server address http://localserver.com. However, it does append the location path, that is, itries to look for http://localserver.com/test, which is not available at all. How can I make the proxy pass to the correct address, throwing out the last part in the location?
That should work. Nginx should strip the '/test' path on the upstream local server. So what I can say is that is not the cause. To make it a bit better, try this:
location /test/ {
proxy_pass http://localserver.com/;
}
The 2 slashes I added at the first 2 lines will avoid mistakenly match '/testABC' and send the wrong request to the upstream local server, for example.
Do you have a
proxy_redirect
line in the same location block? If your upstream local server has redirects, then a mistake on that line will cause an issue like you described.
[UPDATE] Found the root cause why the original config didn't work and mine works: nginx does NOT replace URI path part if the proxy_pass directive does not have a URI path itself. So my fix of adding a slash (slash is treated as a URI path) at the end triggers the URI path replacement.
Reference: http://wiki.nginx.org/HttpProxyModule#proxy_pass
If it is necessary to transmit URI in the unprocessed form then directive proxy_pass should be used without URI part
location /some/path/ {
proxy_pass http://127.0.0.1;
}
try to add as specified here http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass:
proxy_pass http://localserver.com/;
try rewrite
location /test {
rewrite ^ $scheme://$host/;
proxy_pass http://localserver.com;
}
some helpful links...
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite
http://wiki.nginx.org/Pitfalls