I have working openstreet map tile server with only europe imported and one country prerendered. I would like to limit from nginx side to allow request tiles in certain zoom level to by only prerendered parts accessible. Is this somehow achievable from nginx? I need some rules similar to (pseudo syntax):
location /tile/15/(1100 < [0-9]+ < 1200)/(400 < [0-9]+ < 600).png {
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://tiles.backend;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Thank you.
Related
I have a docker with a lizmap that respond in local to the address http://192.168.1.85:8090
I have a nginx that proxy https://geoservizi.pippoepluto.net/ to previous internal url.
I would like to modify https://geoservizi.pippoepluto.net/ -> https://geoservizi.pippoepluto.net/webgis and proxy always to http://192.168.1.85:8090
The problem is that I have to add /webgis/ to all urls to local machine and I do not find the way...
Thanks in advance..
My vhost block:
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://192.168.1.85:8090;
}
Essentially, I would like to be able to proxy https://test.myurl.com/proxy/12345 to https://12345.myurl.com:8443, however, I would like 12345 to be arbitrary.
I have been able to get the proxy pass working with the following (i.e. statically assigned):
location /proxy/12345/ {
proxy_pass https://12345.myurl.com:8443/;
proxy_redirect off;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host "test.myurl.com";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
However, making it arbitrary does not seem to work:
location ~* ^/proxy/([0-9]+)/ {
proxy_pass https://$1.myurl.com:8443/;
proxy_redirect off;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host "test.myurl.com";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
While Nginx accepts my configuration, I get a 404 Not Found. I have looked at a number of other related questions and played around with the config to no avail.
Good afternoon,
I currently have a problem trying to proxy_pass to a url that contains a # sign. I'm assuming it's causing me issues since it's the comment character
the url that works is http://ip:port/remotelogin/#/
and I would like to show up as https://proxy ip/remotelogin/#/
location /remotelogin/#/ {
proxy_http_version 1.1;
proxy_pass "http://ip:port/";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
}
Just replace /remotelogin/#/ with /remotelogin/.
I have been setting up Nginx on my router, and creating subdomains (with CNAMES) to access various components within my network. It has mostly been fairly easy, until I have come to the cameras which are proving to be a problem.
They are basic IP cameras and to date I had opened each one on a different port. They have basic authentication, and once that has been entered I am presented with a live view.
Like all the other components I have set up so far (and they all work) I started by configuring one:
server {
listen 80;
server_name cam.example.co.uk;
location / {
proxy_pass http://192.168.1.101:2001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Hitting cam.example.co.uk from either LAN or WAN gives me a username and password prompt and then the live view loads.
Since there are 9 cameras, I thought it would be a good idea to use /1, /2, /3 etc. at the end to direct me to each one rather can creating subdomains.
server {
listen 80;
server_name cam.example.co.uk;
location /1/ {
proxy_pass http://192.168.1.101:2001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /2/ {
proxy_pass http://192.168.1.102:2002;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
With that I got 404 not found errors, and messages in the logs such as:
"/usr/html/new/index.htm" failed (2: No such file or directory)
Some Googling later I found out that I may need to specify the URI as well in the proxy_pass line, so I changed them to look like:
proxy_pass http://192.168.1.102:2002/new/index.htm;
This then results in the username and password prompt, but when the credentials are entered, all I am left with is a blank screen. It worked fine when it was just location / so no idea why nothing is showing now.
I have a feeling that it is putting the URI in somewhere, but I have no idea where/why or what to do about it.
EDIT
Been Googling and trying various things:
location /1 {
resolver 127.0.0.1;
set $backend "http://192.168.1.101:2001/new/index.htm";
proxy_pass $backend;
proxy_buffering on;
proxy_redirect http://192.168.1.101:2001/new/index.htm http://cam.example.co.uk/1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Then going to this in the browser cams.example.co.uk/1 brings up the username and password prompt, but then displays a blank page. Looking at the Chrome developer tools I can see unexpected token errors, and it looks like it isn't loading the .js files properly.
If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive.
Try this:
server {
listen 80;
server_name cam.example.co.uk;
location /1/ {
proxy_pass http://192.168.1.101:2001/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect http://192.168.1.101:2001/ http://cam.example.co.uk/1/;
}
location /2/ {
proxy_pass http://192.168.1.102:2002/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect http://192.168.1.101:2002/ http://cam.example.co.uk/2/;
}
}
Source: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
Issue:
I have two applications served by one nginx 1.5.5 webserver on one domain, www.domain.com.
Because they both listen on the same locations I added a header of APP = ONE or TWO which I set when the application is first called. Example below.
location ^/APPONE {
proxy_pass http://APPONE;
add_header APP ONE;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ^/APPTWO {
proxy_pass http://APPTWO;
add_header APP TWO;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Due to poor application design, the applications both request the below locations not using the application name as a docroot. Like the example below.
location ~ ^/(framerwork1/|framerwork2/|framerwork3/) {
proxy_pass http://APPONE;
add_header APP ONE;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ ^/(framerwork1/|framerwork2/|framerwork3/) {
proxy_pass http://APPTWO;
add_header APP TWO;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
So, I added the APP ONE or TWO header to separate the two, but my if statements to proxy them based on the header is not being accepted by Nginx. Example Below.
if ($http_host ~ 'APP=ONE') {
location ~ ^/(framerwork1/|framerwork2/|framerwork3/) {
proxy_pass http://APPONE;
add_header APP ONE;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
if ($http_host ~ 'APP=TWO') {
location ~ ^/(framerwork1/|framerwork2/|framerwork3/) {
proxy_pass http://APPTWO;
add_header APP TWO;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Question: How can I proxy these two application successfully based on the header? Please note, I am unable to use a different server block or domain. They must be the same.
Thanks in advance.
Ok, so a request is coming in to www.domain.com/APPONE . You don't say exactly what is being requested through the URL www.domain.com/framerwork1/ but lets imagine it's an image that is required by the page served at /APPONE as that is simple to understand.
When you are setting the header through 'add_header' it is being set in the second array in "Client" -> Nginx -> PHP Proxy.
When the client then makes the request to the image at www.domain.com/framerwork1/ it has no idea that you are hoping to have a header set to be able to determine if the image was requested by APPONE, or something else.
Even if you set the header on the response for www.domain.com/APPONE clients do not blindly echo headers sent to them back to server for subsequent requests.
Or to put it bluntly, I think you've misunderstood where the headers are being passed, and that there isn't really a way to determine what application is making a request to the /framerwork1/ URL like that. You have to do this either via separate domain names (or sub-domain) or by doing it inside your application with things like looking at which application the user is logged into.