I need configure spark web-ui with nginx .
My configuration
location /app/spark/master {
proxy_pass http://192.168.230.45:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
but when i try to access the url, the images and css are not loaded(404 not found).
Now assume the images and css files in static folder of my remote machine(192.168.230.45) but the url points to static folder of my nginx installed machine.
http://localhost/static/img1.png
instead
http://192.168.230.45/static/img1.png
I've lost a couple of days being looking for solution. Finally I've found out how to resolve this problem.
Here is my resolution of our issue:
location /app/spark/master/ {
proxy_pass http://192.168.230.45:8080/;
proxy_set_header Accept-Encoding "";
sub_filter "/static/" "/app/spark/master/static/";
sub_filter_once off;
}
In addition You'll face there similar problem with "history"-like links.
Solution will be the same. Just add the line:
sub_filter "/history/" "/app/spark/master/history/";
And voila!
I also had the same problem, you should use it as root:
app/spark/master => /
location / {
proxy_pass http://192.168.230.45:8080;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/pwds;
}
or you will need to set a pattern correction;
rewrite ^/(.*) https://$server_name/$1 permanent;
Related
I use OpenResty in my project and faced issue that nginx ignores access_by_lua_file when use proxy pass. Here is my code of location:
location /getapi {
internal;
set $apiauth '';
set $api_host '';
access_by_lua_file /usr/local/openresty/nginx/conf/lua/getapi.lua;
proxy_redirect default;
proxy_pass $api_host;
proxy_ssl_certificate "/usr/local/openresty/nginx/conf/cert.pem"
certificate_key "cert.key";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Authorization $apiauth;
}
I call this location with ngx.location.capture. In lua file i define variables apiauth and api_host. But contents of lua file never executes, nginx just ignores it. And no errors in error.log. The only one is that i try to GET empty URL. How can i force nginx to execute contents of access_by_lua_file?
Thanks to #IvanShatsky. Rewrite_by_lua works fo me.
I'm trying to have Wordpress installed in other folder than "/public" on Laravel project.
The laravel path:
/home/forge/domain.com/
Wordpress path:
/home/forge/blog.domain.com/
But I want to use this url and not as subdomain:
domain.com/blog
You can use a location section in your nginx configuration file:
location ^blog/ {
root /home/forge/blog.example.com;
//your regular nginx configuration
}
You may also use a reverse proxy. This means you have to put the blog on a different URL (like blog.domain.com) and then point blog/ to that URL. For example:
location ^blog/ {
sub_filter_types *;
sub_filter_once off;
sub_filter 'blog.example.com' 'www.example.com/blog';
proxy_pass http://blog.example.com/;
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 Accept-Encoding "";
proxy_redirect http://blog.example.com http://www.example.com;
}
The subfilter rewrites all URLs in your html output. The proxy_redirect makes sure cookies and headers are corrected as well.
I am trying to set my root(/) location to be passed to a google bucket.
Here is my configuration:
listen 80;
location / {
rewrite /(.*) /$1 break;
proxy_pass https://storage.googleapis.com/my-google-bucket-name/$1$is_args$args;
proxy_redirect off;
index my_main.html;
proxy_set_header Host "storage.googleapis.com";
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
This seems to work but the index directive does not set the default page (to my_main.html)
e.g. when i go to http://my_enginx_url/ instead of reaching "my_main.html" i reach the google bucket root page that shows an XML file with all the files in that bucket.
P.S
Both
http://my_enginx_url/another_page.html,
http://my_enginx_url/yet_another_page.html
are working fine.
Any ideas?
Because the index directive tells Nginx the names of files to look for within your file system which are appropriate for serving a request ending with a /
You are proxying the request to another server, so it's not applicable here.
To achieve your desired result create another location directive above your current one and use = to tell Nginx this is to handle only requests for an exact match with http://my_enginx_url/
Something like this:
location = / {
proxy_pass https://storage.googleapis.com/my-google-bucket-name/my_main.html;
......
}
I have Jenkins running inside my Glassfish installation, so Jenkins can be reached #
http://localhost:8090/jenkins/
I managed to setup nginx so Jenkins can be reached from the outside #
http://build.example.com/jenkins/
This setup works well so far, but I am not really happy with it. What I would really want to achieve is to hit
http://build.example.com
in the browser to reach Jenkins.
Here is my current nginx config:
server {
listen 80;
server_name build.example.com;
location / {
proxy_pass http://localhost:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
I hope this is possible via some url rewrite, but I'm totally clueless how to do it...
Then change:
proxy_pass http://localhost:8090;
to
proxy_pass http://localhost:8090/jenkins/;
Reference: http://nginx.org/r/proxy_pass
It seems to me the problem is the Glassfish configuration.
How about setting in application.xml the following value:
<context-root/>
Instead of the default, which is the name of the WAR file, without the .war extension.
There seems to be similar questions on SO.
From http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
location / {
rewrite /jenkins/(.*) /$1 break;
proxy_pass http://localhost:8090/jenkins/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
I have an odd issue which is only affecting one local app I'm working on - other apps with this approach seem to work fine (Ghost). This is from my Nginx server config:
location #node_proxy {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://127.0.0.1:5000;
}
location / {
try_files #node_proxy =404;
}
As I said, I have Ghost running identically to this and it performs fine. However for this config it results in every request being a 404 - it seems to never hit the proxy. I've checked logs and this confirms my suspicions, no entries in the access or error logs.
The app I'm proxying through to in this instance is just a simple Express based node app, so nothing complex. Visiting http://127.0.0.1:5000 I see the expected results.
If I change my config to:
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://127.0.0.1:5000;
}
It works as expected, however I'd like to make use of the named location so as to avoid having to repeat proxy declarations.
Have I missed something obvious?
Try this kind of hack:
location #root {
...
}
location / {
error_page 418 = #root; return 418; # redirect to #root
}
Seems like it is impossible to jump to named location from a regular one. You also can try try_files #root #root, however Igor Sysoev (nginx's author) says that error_page is better since it uses less resources.