I have a Nuxtjs app with nginx that running via docker-compose on VPS and it was running ok on 80 port and I could access it with my domain but only with HTTP.
So I needed to install SSL-certificates with certbot and I tried a lot to follow many different tutorials.
I already asked a question about it here and I was advised to read this Medium tutorial. So I did everything as said and it's worked, now I have redirect from http to htttps even if I try to reach my app not through domain but directly via IP address.
But the page is Bad Gateway on https://example.com. But I can reach my app if I go on http://example.com:3000, so I think I messed up with nginx configs.
Here is my files:
- My Dockerfile:
FROM node:12.18.3-alpine
RUN mkdir -p /usr/src/nuxt-app
WORKDIR /usr/src/nuxt-app
RUN apk update && apk upgrade
RUN apk add git
COPY . /usr/src/nuxt-app/
RUN npm install
RUN npm run build
EXPOSE 80
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3000
CMD [ "npm", "start" ]
- My docker-compose.yml:
version: "3"
services:
nginx:
image: nginx:1.15-alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./data/nginx:/etc/nginx/conf.d
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
command: '/bin/sh -c ''while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;"'''
certbot:
image: certbot/certbot
volumes:
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
nuxt:
image: sda2000den/agency:0.4 #<--- my nuxt app
container_name: nuxt_app
ports:
- "3000:3000"
- And finally my nginx config file:
server {
root /var/www;
listen 80;
server_name studioagnc.com;
gzip on;
gzip_types text/plain application/xml text/css application/javascript;
gzip_min_length 1000;
location / {
proxy_pass http://127.0.0.1:3000;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
server {
listen 443 ssl;
server_name studioagnc.com;
ssl_certificate /etc/letsencrypt/live/studioagnc.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/studioagnc.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location / {
proxy_pass http://studioagnc.com; #for demo purposes
}
}
I'm not really friendly with nginx and I do not fully understand what this config does. What can I do to make it work properly?