404 Docker reverse proxy accessing reverse-proxy location - nginx

I am working with docker containers with reverse proxy for jenkins container and got into this issue.
My nginx custom config is as follow:
upstream jenkins {
server 172.17.0.2:8080;
}
server {
listen 80;
server_name jenkins;
location /jenkins {
proxy_pass http://172.17.0.2:8080;
}
Also, /etc/nginx/nginx.conf doesn't have any default root directory but still when I tried to access http://localhost/jenkins, it is giving me 404 with Problem accessing /jenkins. Reason:Not Found
I checked nginx error logs and it has "/etc/nginx/html/index.html" is not found
Though I have not set any /etc/nginx/html/ config, why it is giving me 404 error?
Can someone clarify my doubt?
ScreenShot

Something like this seems more approriate for the nginx part. If you declare an upstream, use it :
upstream jenkins {
server 172.17.0.2:8080;
}
server {
listen 80;
server_name jenkins;
location /jenkins {
proxy_pass http://jenkins;
}
}
For the docker part, I recommand using port mapping if you can. Because IP of docker containers change, you will have to edit you config file each time you recreate the jenkins container. With something like docker container run -d -p 127.0.0.1:8080:8080 my-jenkins-container-image you can modify your nginx config to something like :
upstream jenkins {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name jenkins;
location /jenkins {
proxy_pass http://jenkins;
}
}

Related

NGINX This site can’t be reached

I have a front-end react app, that runs at localhost:3000. And a back-end that runs at localhost:9900.
I can access my back-end with a postman's(or curl) localhost:80/api request.
But I can't access either the site or the server via the web address: my-1stconnection.lan.test.
What's the problem?
NGINX config:
server {
listen 80;
listen [::]:80;
server_name my-1stconnection.lan.test;
location / {
proxy_pass http://localhost:3000/;
}
location /api {
proxy_pass http://localhost:9900/;
}
}
I forgot one important thing in order to activate the local server:
127.0.0.1 my-1stconnection.lan.test into /etc/hosts
After this fix, everything started working.

Running Zeppelin with https using Nginx context routing

I have a requirement to run the services (Zeppelin, grafana etc) using https. I have installed certificates and added below configuration to NGINX.
But still it is not working, please let me know if any other configuration to be added. Thanks!
server {
listen 443 ssl;
ssl on;
ssl_certificate ../crt/*****.crt;
ssl_certificate_key ../crt/*****.key;
.
.
.
location /zeppelin {
proxy_pass http://127.0.0.1:8080/#/;
}
}
Configure the zeppelin IP in upstream and use the upstream name in proxy_pass like below
upstream zeppelin {
server 127.0.0.1:8080;
}
server {
....
location / {
proxy_pass http://zeppelin;
}
....
}
To host zeppelin under 'zeppelin' context you have to change the zeppelin.server.context.path property in conf/zeppelin-site.xml
Configuring zeppelin using nginx needs more configuration like websocket proxying. You can refer the sample nginx configuration in this link

Elixir/Phoenix umbrella app with two apps and access through subdomain mapped through reverse proxy with nginx

It's several hours I'm trying but I don't know what I'm doing wrong. I'm on a server with ubuntu 16.04, I have an umbrella app with two apps in it, which I would like to map to frontend.example.com and backend.example.com. On the DNS I have a wildcard for the whole domain (*.example.com + #.example.com). An additional issue is that one of them has to be on HTTPS,so I have the following onstart:
09:45:38.013 [info] Running FrontendWeb.Endpoint with Cowboy using http://0.0.0.0:91
09:45:38.055 [info] Running FrontendWeb.Endpoint with Cowboy using https://0.0.0.0:445
09:45:38.199 [info] Running BackendWeb.Endpoint with Cowboy using http://0.0.0.0:90
I would like Frontend to be mapped to frontend.example.com and the like for the second one. I have this servers.conf under /etc/nginx/conf.d:
server {
listen 80;
server_name backend.example.com;
location / {
proxy_pass http://localhost:90;
...
}
server {
listen 80;
server_name frontend.example.com;
location / {
proxy_pass http://localhost:91;
...
}
server {
listen 443;
server_name frontend.example.com;
location / {
proxy_pass http://localhost:445;
...
}
Is there something missing? It's not really working, only the backend redirect partially works.
EDIT: Should I put something in sites-available too? or the conf file is enough?

nginx host not found in upstream

I tried to follow the instructions here, but I still can't seem to get it to work. As with the question, I don't expect some of the servers to be running at the time of starting nginx. I would actually prefer if instead a local 404 html were returned if the server was not running.
upstream main {
server my_main:8080;
}
server {
listen 80;
server_name www.my_site.com my_site.com;
location / {
resolver 8.8.8.8 valid=30s;
set $upstream_main main;
proxy_pass http://$upstream_main;
}
}

How to rewrite URL to match a server using nginx?

I'm new to nginx. I have two projects, and the one is django web app which is running localhost 8000, and another is tornado which used to provide api service and running localhost 8888.
How do I config the nginx that redirects all the url requests(from 80 port) to localhost:8000 but /api requests to localhost:8888(tornado app)?
Edit your nginx config file. Add a server block and use proxy_pass in location blocks to proxy (redirect) the request.
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:8000;
}
location /api {
proxy_pass http://127.0.0.1:8888;
}
}
Save it, and reload nginx.
nginx -s reload
https://gist.github.com/soheilhy/8b94347ff8336d971ad0

Resources