Bitbucket over http nginx proxy - http

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.

Related

nginx reverse proxy multiple external sites hosted on different port to same port, different subdomain?

This may have been answered many times before but most answers are site specific so wanted some insight on a bareboned nginx config on how to redirect multiple external sites under same server but different subdomain. Pls note the external sites are inaccessible and need the reverse proxy via XYZ to make accessible.
I found existing nginx config already a proxy set up for site1 : AAA proxied through http://XYZ:8088. Below is the existing config. Now, how do I go about adding another site2 to be proxied via http://XYZ:8088/site2
So far, I tried to add additional section at the bottom of config similar to site1 (which is perfectly working fine), however site2 css/images is lost if I try to hit http://XYZ:8088/site2
server {
listen 8088 default_server;
server_name "";
return 444;
}
server {
listen 8088;
server_name "XYZ.example.com";
charset utf-8;
# Deny access to .htaccess files.
location ~ /\.ht {
deny all;
}
# Proxy to site1 server.
location / {
proxy_http_version 1.1;
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-Host $server_name:$server_port;
proxy_pass http://site1;
}
# Proxy to site2 server.
location /site2 {
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://site2/;
}
}
upstream site1 {
server site1:1111;
}
upstream site2 {
server site2:2222;
}
Any help would be appreciated. Also if someone can explain why below config is behaving this way ? I understand it has something to do with the additional "/site2" being used now. But how do I make it ignore that.

Nginx subdomain config for Gunicorn server

I have two servers running on a DigitalOcean droplet. One is a Django/Wagtail application served with Gunicorn (used as a headless CMS), and the other is a SSR Nuxt.js app (front-end). Using the following nginx configuration I’ve made the Nuxt app available at example.com (works great), and now I’m trying to make my Django/Wagtail application available at the subdomain cms.example.com. (I’ve modified my local hosts file so the domain example.com actually functions)
/etc/nginx/sites-available/default
server {
listen 80;
listen [::]:80;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
listen [::]:80;
server_name cms.example.com;
location / {
include proxy_params;
proxy_pass http://unix:/home/thomas/daweb/cms/cms.sock;
}
}
/etc/nginx/proxy_params
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;
Result from curl --unix-socket /home/thomas/daweb/cms/cms.sock cms.example.com is html of the default Wagtail landing page, no errors.
However navigating to cms.example.com just gives me a connection error. If I swap the two, I can see the Wagtail interface at example.com, so I know they’re both working. However, I can’t seem to figure out how to configure a subdomain and I struggle to understand the nginx documentation. Also similar questions about configuring subdomains are usually about making static files available, not listening to active ports.
One extra layer of trouble is that the Wagtail CMS is accessible at /admin of its server root, so I’d like to make that page appear at cms.example.com rather than having to navigate to cms.example.com/admin. Any help would be greatly appreciated!
Check what is contained in /etc/nginx/proxy_params. I would expect something like this:
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;
Also, to be sure Gunicorn is working correctly, try:
curl --unix-socket /home/thomas/daweb/cms/cms.sock cms.example.com

Proxy all subdomain to other domain path

How to proxy all subdomain to other domain path?
For example
SUBDOMAIN.abcxyz123.com
To be proxied to
myapp.otherdomain.com/SUBDOMAIN
Making sure that all header/path and query parameters in the request is kept.
Update:
I've tried and have a working config but still not the one I need:
server {
listen 80;
server_name ~^(?<subdomain>.+)\.abcxyz123\.com$;
location / {
proxy_set_header Host "myapp.otherdomain.com";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
# this worked:
proxy_pass http://myapp.otherdomain.com/somepath/;
# this does not work:
#proxy_pass http://myapp.otherdomain.com/$subdomain$request_uri;
}
}
Try this
server {
server_name ~^(?<subdomain>.*)\.abcxyz123\.com$;
resolver 8.8.8.8;
rewrite ^/(.*)$ /$subdomain/$1;
location / {
proxy_set_header Host "myapp.otherdomain.com";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_pass http://myapp.otherdomain.com;
}
}
This should proxy all your traffic with original query parameters(query strings, request body, request method, etc), I changed the host header to the proxied "myapp.otherdomain.com" incase the server of 'myapp.otherdomain.com' has more than one virtual hosts. If you don't want the change, use $host instead.
This answer might need another edit since your question isn't very clear. If you have further question, comment and i will edit in my answer.

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.

Jenkins behind nginx without subdirectory

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

Resources