How to reverse proxy
Hi there, I want to hace my app reverse proxied using default swag config and it returns with 502 bad gateway. Please tell me how to do it properly or anything i need to change. I tried both subfolder and subfile, nothing works. I have gone through your readme so many times, there is no mention of path url? am I missing something?
Can you share the config you are currently using ? I think it would be a good starting point to try to see what is wrong.
## Version 2023/02/05
# REMOVE THIS LINE BEFORE SUBMITTING: The structure of the file (all of the existing lines) should be kept as close as possible to this template.
# REMOVE THIS LINE BEFORE SUBMITTING: Look through this file for <tags> and replace them. Review other sample files to see how things are done.
# REMOVE THIS LINE BEFORE SUBMITTING: The comment lines at the top of the file (below this line) should explain any prerequisites for using the proxy such as DNS or app settings.
# make sure that your <container_name> container is named <container_name>
# make sure that <container_name> is set to work with the base url /<container_name>/
location /slideshow {
return 301 $scheme://$host/slideshow/;
}
location ^~ /slideshow/ {
# enable the next two lines for http auth
auth_basic "Restricted";
auth_basic_user_file /config/nginx/slideshow.htpasswd;
# enable for ldap auth (requires ldap-server.conf in the server block)
#include /config/nginx/ldap-location.conf;
# enable for Authelia (requires authelia-server.conf in the server block)
#include /config/nginx/authelia-location.conf;
# enable for Authentik (requires authentik-server.conf in the server block)
#include /config/nginx/authentik-location.conf;
include /config/nginx/proxy.conf;
include /config/nginx/resolver.conf;
set $upstream_app slideshow;
set $upstream_port 5800;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
}
# REMOVE THIS LINE BEFORE SUBMITTING: Some proxies require one or more additional location blocks for things like API or RPC endpoints.
# REMOVE THIS LINE BEFORE SUBMITTING: If the proxy you are making a sample for does not require an additional location block please remove the commented out section below.
# location ^~ /<container_name>/api {
# include /config/nginx/proxy.conf;
# include /config/nginx/resolver.conf;
# set $upstream_app <container_name>;
# set $upstream_port <port_number>;
# set $upstream_proto <http or https>;
# proxy_pass $upstream_proto://$upstream_app:$upstream_port;
#
# # REMOVE THIS LINE BEFORE SUBMITTING: Additional proxy settings such as headers go below this line, leave the blank line above.
# }
Note I had auth on and off and tested it and still nothing. I get the page to put in my username and pass, so it must be working but after I put my details getting that error.
I used this template from swag folder.
link for same thing is here:
https://github.com/linuxserver/reverse-proxy-confs/blob/master/_template.subfolder.conf.sample
From
https://github.com/oneclickvirt/dockerfile-templates/tree/main/idea
and
https://github.com/jlesage/docker-crashplan-pro?tab=readme-ov-file#routing-based-on-url-path
I want to use a custom path for reverse proxy access to a container based on the jlesage/baseimage-gui:ubuntu-22.04-v4 base image, instead of using the default root path /
- Use NGINX as a reverse proxy to map the IDEA plugin container’s service to the path
/ide/ - Avoid exposing the IDEA container’s port directly to the public network
- Use Docker custom network to enable inter-container communication
Create a custom network named web-net to enable communication between containers:
docker network create web-net
Start the IDEA container without exposing any ports, connect it to the web-net network (the container's web port is set to 31000 at the Dockerfile stage):
docker run -d \
--name idea \
--network web-net \
jetbrains-idea-plug-cuda:v2024.2.5
Create a file named default.conf in the current directory with the following content:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream idea_app {
# Use the reachable container name for reverse proxy
server idea:31000;
}
server {
listen 80;
server_name _;
location = /ide {
return 301 $scheme://$http_host/ide/;
}
location /ide/ {
rewrite ^/ide(/.*)$ $1 break;
proxy_pass http://idea_app/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
}
}
Create a file named Dockerfile in the current directory with the following content:
FROM nginx:alpine
COPY default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Build the custom NGINX image and run the container, connect it to the web-net network, and map port 80 of the container to port 31000 on the host:
docker build -t custom-nginx-proxy .
docker run -d \
--name nginx-proxy \
--network web-net \
-p 0.0.0.0:31000:80 \
custom-nginx-proxy
Now can access the service via http://<host-ip>:31000/ide/
Here's my solution, not sure if it meets OP needs.