I try to use NGINX as a reverse proxy for my Jenkins server. Basically when http://host/jenkins gets opened in the browser NGINX should proxy the request to http://host:8080 where Jenkins is listening.
I tried various different configurations but none really works. Here the location configuration that I use at the moment. It somehow works, but does not show any images, etc..
location /jenkins/ {
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 X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8080/;
proxy_read_timeout 90s;
# Fix potential "It appears that your reverse proxy set up is broken" error.
proxy_redirect http://localhost:8080/ https://host/jenkins/;
}
Make sure to update your Jenkins configuration
JENKINS_ARGS="--webroot=/var/cache/jenkins/war --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT --prefix=/jenkins"
Taken from https://wiki.jenkins.io/display/JENKINS/Jenkins+behind+an+NGinX+reverse+proxy
Related
First things first, I'm quite a beginner at hosting shiny apps on docker and shinyproxy. The terms I use might be a bit layman and incorrect.
I have my application running well on shinyproxy and can be accessed through serveripaddress:8080/app/01_hello.
The problem comes when I try to use a link ie. theapp.company.com instead of the ip address. This is what it shows when I go to the link:
Here is the necessary part of 01_hello nginx configuration file:
location / {
proxy_pass http://localhost:8080/app/01_hello;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 600s;
proxy_redirect off;
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 X-Forwarded-Proto $scheme;
}
But when I change the proxy_pass to:
proxy_pass http://localhost:8080;
then go to theapp.company.com it shows the landing page of all apps on shinyproxy and then I can go to theapp.company.com/app/01_hello which works, but not what I want.
I just want it to be theapp.company.com. How do I achieve this?
I have a very similar setup and it works for me. I believe the problem is that you are using "app" instead of "app_direct" in proxy_pass. This is my nginx proxy config (localhost instead of 127.0.0.1 or 0.0.0.0 should be fine):
location / {
proxy_pass http://127.0.0.1:8080/app_direct/mimosa/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 600s;
proxy_redirect off;
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 X-Forwarded-Proto $scheme;
}
Using the /app/ path seems to confuse shinyproxy. If you run shinyproxy via java directly (with your setup) you will see requests that do not match the correct URI. You can also check the console (F12 in chromium), which shows failed loading of resources.
Not sure if this can be fixed easily with the nginx config.
Usually, the navbar at the top is not needed, so app_direct is a simple solution. Hope it helps. If not, can you post your entire nginx config and application.yml? (you can remove sensitive parts)
I have one server with several web services exposed in different ports in docker containers.
With nginx I would like use subpaths to browse througth these servers.
For example:
I have Nextcloud in http://myurl:8080/
Reachable from http://myurl:80/nextcloud.
I tried different solution, probably the most closed to reach the solution is the following:
location /nextcloud/{
proxy_pass http://myurl:8080/;
}
But in this way I lost the first parameter in the url:
instead of proxying on http://myurl/nextcloud/a/b; I'm proxed on http://myurl/nextcloud/b, losing /a
location /nagios/ {
rewrite ^/nagios(/.*)$ $1 break;
proxy_pass http://10.0.21.8:80/;
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 https;
proxy_redirect off;
}
Reference: https://raymii.org/s/tutorials/NGINX_proxy_folder_to_different_root.html
I have the www.site.com and I have the blog.site.com.
On site.com server I have a nginx reverse proxy pointing from www.site.com/blog to www.blog.com and everything works fine, here's the code:
location /blog {
proxy_read_timeout 30s;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $host;
proxy_pass http://blog.site.com;
proxy_redirect off;
}
But when I add the CloudFlare CDN i got the error 1000 because it's another reverse proxy. (https://support.cloudflare.com/hc/en-us/articles/200171976-Error-1000-DNS-points-to-prohibited-IP)
How can I solve that?
This is because cloudflare detected that the site at blog.site.com is hosted at cloudflare too and there is a chance that allowing you to do this will create a request loop.
Possible solutions:
Take one of the hosts off cloudflare;
Proxy directly to the IP address of the host inside nginx.
Code:
location /blog {
proxy_read_timeout 30s;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $host;
proxy_pass http://{Your-Host-IP-Address};
proxy_redirect off;
}
I want to run the application Mattermost in a subfolderconfiguration like
https://www.example.com/mattermost/
location /mattermost/ {
gzip off;
proxy_set_header X-Forwarded-Ssl on;
client_max_body_size 50M;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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 X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://localhost:8065/;
}
With this configuration I'll get passed to the correct application but the application does not recognize the subfolder. It tries to server
https://www.example.com/static/style.css instead of https://www.example.com/mattermost/style.css and brings up a 404 error.
How can I pass also the subfolder to the reverse proxy with nginx?
The application I wanted to get running was "Mattermost". As I now can confirm, the use as subfolder is not possible with the Version
Mattermost Team Edition Version: 3.0.0 (3.0.3)
Further information:
http://forum.mattermost.org/t/blank-page-when-installing-mattermost-with-nginx-proxy-pass-as-subdirectory/1604/8
Update: As confirmed in the forum above, a subfolder configuration is not possible with Mattermost right now.
I try to configure an nginx reverse proxy to access a Jenkins instance. I can open the authentication page but there is no CSS and no image. It works perfectly when direct access.
All works as if the reverse proxy does not rewrite correctly URLs defined in the html source page. Have I missed something ?
Here is my nginx configuration :
location /jenkins {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
proxy_pass http://jenkins:8080/;
}
I found the solution. The nginx reverse proxy works well but Jenkins need some customization to work with reverse proxy.
The final nginx configuration :
location /jenkins/ {
proxy_pass http://jenkins:8080/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;
}
And the tutorial to configure jenkins behind nginx reverse proxy which solved my problem
I don't know if above statement worked for OP but I know that altering location name line did the trick for me:
location ^~ /jenkins/ {
proxy_pass http://jenkins:8080/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;
}
If you use the Jenkins with docker. You can add the environment part of compose file as below:
environment:
JENKINS_OPTS: "--prefix=/jenkins"
in the nginx conf file. proxy_pass must refer to the http://IP-ADDRESS:PORT/jenkins/. As mentioned before, the link as a reference is very usefull.