Skip to content

Instantly share code, notes, and snippets.

@2called-chaos
Last active April 6, 2024 23:58
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2called-chaos/4eacb303b9491d1e374c to your computer and use it in GitHub Desktop.
Save 2called-chaos/4eacb303b9491d1e374c to your computer and use it in GitHub Desktop.
My nginx config for dynmap (on port 8123, that's the dynmap bound to localhost so no direct call possible)
server {
listen 80;
server_name map.geekya.com;
# I normally wouldn't disable the access log but here I see no problem with it
access_log off;
error_log /var/log/nginx/com.geekya.map.error.log;
# custom error page when map isn't available
error_page 502 503 504 =503 /503_map.html;
location = /503_map.html {
root /home/www/com.geekya/current/public;
}
# serve statics
location ~ ^/(tiles|css|images|js)/ {
root /home/geekyamc/_main/plugins/dynmap/web;
expires 0;
add_header Cache-Control private;
break;
}
# forward anything else to the dynmap webserver
location / {
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 off;
proxy_read_timeout 6;
# That is my dynmap webserver which is only accessible via localhost or through nginx
proxy_pass http://127.0.0.1:8123;
break;
}
}
@aaronlockhartdev
Copy link

I still cannot get the proxy forwarding to work. When I type in chat it says its from my nginx server's ip instead of the players. How did you deal with this problem?

@2called-chaos
Copy link
Author

It's been a while and I can't remember if I had that problem. To clarify, players ingame chat and it shows on dynmap as from the server?

When I type in chat it says its from my nginx server's ip instead of the players

That is what the two headers X-Real-IP and X-Forwarded-For are usually there for. But it requires the application on the other side to actually care about these. For the application behind nginx the REMOTE_ADDR will always be nginx (or localhost rather).

And/or are you using the PHP component for chat? Never looked into it but it might just blindly accept REMOTE_ADDR

@GRxRedZero
Copy link

Whats about https? How to use it for Port 443?

@2called-chaos
Copy link
Author

Whats about https? How to use it for Port 443?

Well, same as with any other nginx config :)
I would recommend using certbot, this page here gets you started easily: https://certbot.eff.org/instructions

As reference also take a look at http://nginx.org/en/docs/http/configuring_https_servers.html

@GRxRedZero
Copy link

okay thank you. I got it.

@Hi-ImKyle
Copy link

Hi-ImKyle commented Dec 4, 2020

I know this is a few months old but I'm hoping there's someone that might come across this that knows the answer I'm looking for.

I need more than one dynmap instance behind one Nginx reverse proxy. At the moment this config only allows for one instance but I would like to know if it's possible to do the following:

If anyone knows the solution, either reply here or if you have Discord if you could contact me on that preferably, Kyle#0420

EDIT: Thank you Ben on Discord for helping me out :)

@bamiesking
Copy link

The gist for my nginx.conf file mentioned by Kyle above is here.

@2called-chaos
Copy link
Author

@Hi-ImKyle @bamiesking

I would recommend you to not do this with subdirectories (it will just give you headaches). I would recommend subdomains. You can then proxy_pass to as many different ports/dynmap as you want, each with their own hostname/subdomain.

You can still either make a redirect for // to .domain.tld or iframe the maps on your main page. I did the latter with just a fixed iframe spanning the whole viewport, only downside in that case is that users can't easily copy deeplinks.

@Hi-ImKyle
Copy link

Hi-ImKyle commented Dec 12, 2020

I would recommend you to not do this with subdirectories (it will just give you headaches). I would recommend subdomains.

@2called-chaos My setup doesn't allow that, nor do I want that. But I'll keep it in mind just in case I need it, but everything is working fine here and is easily expandable. Thanks.

@bamiesking
Copy link

@2called-chaos

I would recommend you to not do this with subdirectories (it will just give you headaches).

Is there any reason for this other than preference?

@2called-chaos
Copy link
Author

@bamiesking

Has been a while with dynmap for me and it might just work with it in this case but many web applications don't like it do be in a subdirectory. You then have to start rewriting URLs and then you might have emails with wrong links or some other edge cases.

@Griefed
Copy link

Griefed commented May 22, 2021

Thank you for this. I've been smashing by head through my keyboard trying to get my nginx to work with a remote dynmap server. This helped a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment