After some discussions with another dev ops team member, it became apparent that installing swagger-ui manually would be the best way to run it. With that in mind, here’s how I did it:

Clone swagger-ui

Swagger-ui is available on github at https://github.com/swagger-api/swagger-ui. Clone it to your ec2 instance

git clone https://github.com/swagger-api/swagger-ui.git

cd into the dist directory

cd swagger-ui-watcher/dist

Open the index.html file, search for the “petstore” api url, and change it for our url. Copy the dist directory to the nginx directory, for us this is /usr/share/nginx/html/. set up nginx to direct traffic to the directory you just copied. Example is below:

server {
        listen   80;
        server_name ourdomain.co.uk;
        root /usr/share/nginx/html;

        location / {
                add_header 'Access-Control-Allow-Origin' '*';
                return 301 https://$host$request_uri;
        }
        location ~ /.well-known {
                allow all;
        }
}

server {
        listen 443 ssl;
        server_name ourdomain.co.uk;
        add_header 'Access-Control-Allow-Origin' '*';
        root /usr/share/nginx/html/swagger-ui/;
        ssl_certificate /etc/letsencrypt/live/ourdomain.co.uk/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/ourdomain.co.uk/privkey.pem; # managed by Certbot
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
        index index.html index.htm;

        location / {
                try_files $uri $uri/ /index.html;
        }
}

Restart nginx:

sudo service nginx restart

You should now be able to see the swagger definition via the domain specified. In our example it’s: https://ourdomain.co.uk/