script-server
script-server copied to clipboard
Nginx with script-server in a docker container
I have an issue with my configuration and Nginx. I have a server with multiple Docker containers running different web applications. Let's say the server domain name is examplescriptserver.com. I also have an Nginx reverse proxy installed directly on the server (not in a Docker container) that routes to these applications, such as code-server, and it works well. However, I'm having an issue with script-server when it's in a Docker container (when it's installed directly on the server, it works fine). When I'm accesing to https://examplescriptserver.com/example1/, I get redirected to127.0.0.1:5000/index.html.
I've also tried changing the proxy_pass to the docker's internal ip (172.0.18.2), but in this case, it redirects me to that ip.
Here's my server configuration
My Nginx configuration:
server {
listen 80 default_server;
server_name examplescriptserver.com;
return 301 https://$host$request_uri;
}
server {
server_name examplescriptserver.com;
# Script-server
location ^~ /example2/ {
proxy_pass_header Server;
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5000/;
# needed for websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin http://$proxy_host;
}
# code-server
location /example1/ {
proxy_pass http://localhost:1234/;
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_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
listen [::]:443 ssl;
listen 443 ssl;
ssl_certificate /etc/ssl/cert.pem;
ssl_certificate_key /etc/ssl/key.pem;
}
And my Docker Compose file for Script-server is:
services:
script-server:
ports:
- 127.0.0.1:5000:5000
volumes:
- '/var/run/docker.sock:/tmp/docker.sock:ro'
- '/opt/script-server/conf/.htpasswd:/app/conf/.htpasswd'
- '/opt/script-server/conf/conf.json:/app/conf/conf.json'
- '/opt/script-server/runners/:/app/conf/runners'
- '/services/scripts/:/app/scripts/'
restart: always
logging:
options:
max-size: 1g
container_name: script-server
image: 'bugy/script-server:latest'
Thanks for any help
Hi @klaertus, could you try to do one of the following things:
- Add
proxy_set_header X-Scheme $scheme;directive to Script server nging configuration - Change script server code as per https://github.com/bugy/script-server/issues/640#issuecomment-1485589667
You can try either 1 or 2. Or both of them together.
To be honest my network/protocol knowledge is not very high, and I don't know how those redirects are supposed to work, so I don't have clear understanding, how nginx handles those (and why it doesn't substitute paths properly)
Hello @bugy,
Just changing the code like https://github.com/bugy/script-server/issues/640#issuecomment-1485589667 solved my problem.
Thanks !
Thanks for confirming @klaertus. Did you try setting X-Scheme?
Yes, but whether I set it or not didn't make any difference.
I see, thanks!