Skip to content

Commit

Permalink
feat(deploy-tool): add nginx proxy for https
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed May 16, 2024
1 parent 27bf74b commit d56d33f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
17 changes: 13 additions & 4 deletions deploy-web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ RUN apt-get update
RUN apt-get install libcap2-bin -y
RUN setcap cap_net_bind_service=+ep `readlink -f \`which node\``

USER nextjs
# Setup nginx for HTTPS
RUN apt-get install nginx -y
RUN mkdir -p /etc/nginx/ssl
RUN openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout /etc/nginx/ssl/my_ssl_key.key -out /etc/nginx/ssl/my_ssl_cert.crt -subj "/CN=cloudmos.io" -days 600
COPY nginx.conf /etc/nginx/nginx.conf
RUN nginx -t

#USER nextjs

#EXPOSE 3001
EXPOSE 80
EXPOSE 443

#ENV PORT 3001
ENV PORT 80
ENV PORT 3001
#ENV PORT 80

CMD ["node", "server.js"]
#CMD ["node", "server.js"]
CMD sed -i "s/127.0.0.1/$(hostname -i)/" /etc/nginx/nginx.conf && service nginx start && node server.js
34 changes: 34 additions & 0 deletions deploy-web/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# nginx.conf

events {
}

http {
server {
# Redirect HTTP requests to HTTPS.
listen 80;

return 307 https://$host$request_uri;
}

server {
listen 443 ssl;

server_tokens off;

ssl_certificate /etc/nginx/ssl/my_ssl_cert.crt;
ssl_certificate_key /etc/nginx/ssl/my_ssl_key.key;

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:3001;
proxy_buffers 8 16k;
proxy_buffer_size 16k;
proxy_cookie_path / "/; HTTPOnly; Secure";
}
}
}

0 comments on commit d56d33f

Please sign in to comment.