Jenkins behind nginx without subdirectory - nginx

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;
}

Related

I want to host a static website on EC2 with nodejs app too

I am trying to host a static website on EC2 but no luck.
here is my config file node
server {
listen 80;
server_name localhost;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://127.0.0.1:3000";
}
}
I want to host static website too.
How can I do that on EC2
I'm not sure how I can explain it end to end. I hope you got a basic idea of how it works.
From your question, I can understand that you are having some problems with the Nginx configuration.
your Nginx config file should look like this,
location / {
# This would be the directory where your frontend code resides
root /var/www/html/;
try_files $uri /index.html;
}
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:3000/;
proxy_set_header Host $http_host;
proxy_redirect off;
}
You can use PM2 for running the nodejs app in your VM.
Here Nginx would be webserver for your frontend application and a proxy to your backend application, all the request is going to hit on your Nginx server.
I hope this is what you are looking for.

Bitbucket over http nginx proxy

I have a bitbucket server that works on a direct IP address very well. But I want to access my bitbucket server using subdomain name and over HTTP, something like bitbucket.subdomain.com
I have found a very good official Atlassian's explanation on how to do it and started from adding new server parameters to the bitbucket.properties
server.port=7990
server.secure=true
server.scheme=http
server.proxy-port=80
server.proxy-name=bitbucket.mydomain.com
server.context-path=/
everything looks clear to me, so I've decided to change my Nginx configuration and added next server settings
#Bitbucket
server {
server_name bitbucket.mydomain.com;
# serve static files directly
#location for bitbucket
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:7990;
}
}
the same looks cool for me.
Did all restarts/reload etc and going in my browser to bitbucket.subdomain.com and I see 404
So, I'm really stuck, since I've done a lot of different changes and no, it's not working
Can anyone help?
I try the same stuff and this works for me:
Bitbucket.properties:
server.port=7990
server.scheme=http
server.proxy-port=80
server.proxy-name=bitbucket.mydomain.com
Nginx
server {
listen 80;
server_name bitbucket.mydomain.com;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:7990/;
client_max_body_size 10M;
}
}
Then restart both and you are ready to go.
V.

From Nginx subpath to root in different port

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

nginx reverse proxy and paths

This is the issue I'm having with this application that we cannot modify:
Example:
I'm trying to set this app so that it goes to:
reverseproxy.com/app1/ which should redirect to:
reverseproxy.com/app1/index.html
However, when the app does a redirect it goes
reverseproxy.com/index.html which throws a 404. (note its missing "app1" in the path)
I've been having a hard time finding a clear answer on this. I assume that it must be something I am missing, here is my current conf:
location /app1 {
proxy_pass https://applicationserver.com/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Any help would be appreciated.
Thanks
Jon

nginx reverse proxy images and css are not loaded

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.

Resources