Skip to content

Configuring Nginx

Arnold Noronha edited this page Sep 5, 2021 · 3 revisions

We suggest putting Screenshotbot behind an Nginx web server.

Simple configuration

server {
     listen 80;
     server_name screenshotbot.example.com;

     proxy_set_header Host $host:$server_port;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Forwarded-Proto $scheme;

     location / {
          proxy_pass http://127.0.0.1:4091;
          proxy_redirect http://$proxy_host:$proxy_port https://$host;
     }
}

Future work: Hosting on subdirectories

In the previous example configuration, we hosted Screenshotbot at screenshotbot.example.com. In theory we might be able to host on example.com/screenshotbot instead. However, we don't support this at the moment. Several things might break, including cookies, or the CLI tool. If you're planning to use subdirectories, please do reach out to us, and we'll debug all the breaking things to fix all the issues. (I'm open to supporting this, I just want to make sure somebody actually needs it first.)

HTTPS using Certbot

We highly recommend using HTTPS on your domain. With Certbot getting an HTTPS certificate is free and easy.

If you used the configuration above, simply install certbot and the Nginx certbot plugin (on Debian/Ubuntu: apt install certbot python-certbot-nginx). Then on the command line type sudo certbot. Certbot will look through your Nginx configuration and find all your domains, and ask you which domains you want certificates for. Follow the instructions, and Certbot will create valid certificates and also update your nginx configuration to use the new certificate. Certbot will also automatically renew certificates when they expire.