Skip to content

nginx Reverse Proxy

tkSimon edited this page Jul 30, 2016 · 3 revisions

If you do not want to expose pokemongo-map to the web directly or you want to place it under a prefix, follow this guide:

Assuming the following:

  • You are running pokemongo-map on the default port 5000
  • You've already made your machine available externally (such as with ngrok)
  1. Install nginx (I'm not walking you through that, google will assist) - http://nginx.org/en/linux_packages.html
  2. In /etc/nginx/nginx.conf add the following before the last }.
    (Note: this is not required if the last line of your nginx.conf file has this: include /etc/nginx/conf.d/*.conf;
 include conf.d/pokemongo-map.conf;
  1. Create a file /etc/nginx/conf.d/pokemongo-map.conf and place the following in it:
  • create pokemongo-map.conf nano /etc/nginx/conf.d/pokemongo-map.conf
  • If you want to access your maps at www.YourDomain.com/go/: (note the trailing slash!)
      location /go/ {
         proxy_pass http://127.0.0.1:5000/;
      }
      location / {
         proxy_pass http://127.0.0.1:5000/;
      }
  1. Test your nginx config: service nginx configtest
  2. Reload/Restart your nginx service: service nginx restart
  3. You can now access it by http://yourip/go or http://yourip

###Add a free SSL Certificate to your site:

  1. https://certbot.eff.org/#debianjessie-nginx
  2. For webroot configuration, simplest for this use, do the following:
  • Edit your /etc/nginx/conf.d/pokemongo-map.conf
  • Add the following location block:
 location /.well-known/acme-challenge {
   default_type "text/plain";
   root /var/www/certbot;
 }
  1. Create the root folder above mkdir /var/www/certbot
  2. Set your permissions for the folder so that nginx can access the folder
  • Either chown -R www-data:www-data /var/www/certbot
  • or chown -R nginx:nginx /var/www/certbot
  • you can figure out which one but looking at nginx.conf (the first line says either user nginx or user www-data)
  1. Run certbot certonly -w /var/www/certbot -d yourdomain.something.com
  2. Certificates last for 3 Months and can be renewed by running certbot renew

###Example Config with SSL Cert

server {
    listen       80;
    server_name  PokeMaps.yourdomain.com;

   location /.well-known/acme-challenge {
     default_type "text/plain";
     root /var/www/certbot;
   }

  #Forces all other requests to HTTPS
  location / {
     return      301 https://$host$request_uri;
  }

}

server {
  listen 443 ssl http2;
  server_name PokeMaps.yourdomain.com;

  ssl_certificate /etc/letsencrypt/live/xxxxxxxxxxxxxxxxxxxxxx/fullchain.pem; #add this after you run CertBot
  ssl_certificate_key /etc/letsencrypt/live/xxxxxxxxxxxxxxxxxxxxxx/privkey.pem;  #add this after you run CertBot

  location /go/ {
   proxy_pass http://127.0.0.1:5000/;
   proxy_redirect off;
  }