sudo amazon-linux-extras install -y nginx1Configure SSL
Putting nginx in front
An app that binds to 127.0.0.1 (the pattern used by baseball-trajectory in Install Apps and daemonized in Lab 10) isn’t reachable from outside its own instance. Something has to accept the connection on 443, terminate TLS, and forward the request inward.
Installing nginx
Install nginx:
Writing the server block
The server block points at Let’s Encrypt certificate files, so request them first. Install certbot from EPEL and ask for a certificate for the hostname (port 80 must be open in the security group, and nginx must not be running yet, because --standalone binds to that port itself):
sudo amazon-linux-extras install -y epel
sudo yum install -y certbot
sudo certbot certonly --standalone -d trajectory.example.comCreate the site configuration:
sudo vim /etc/nginx/conf.d/baseball-trajectory.confGive it a server block that listens on 443, loads the certificate, and proxies to the app on 8000:
server {
listen 443 ssl;
server_name trajectory.example.com;
ssl_certificate /etc/letsencrypt/live/trajectory.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/trajectory.example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}The certificate paths assume you have a hostname pointed at the instance, covered in Configure DNS.
Testing and starting nginx
Test the configuration before reloading, since a syntax error will otherwise take nginx down entirely:
sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulEnable and start it in one command, the same enable --now used for the app:
sudo systemctl enable --now nginxLoad the hostname in a browser and you should get the app’s landing page, served over HTTPS.
Recap
An app bound to
127.0.0.1isn’t reachable from outside its instance, songinxaccepts the connection on443, terminates TLS, and forwards the request tohttp://127.0.0.1:8000.Run
sudo nginx -tbefore reloading, because a syntax error will otherwise takenginxdown entirely. Thensystemctl enable --now nginxstarts it with the same pattern as the app.The
proxy_http_version,Upgrade, andConnectionlines keep Shiny’s WebSocket connection open. Leave them out and the page loads, then nothing responds.