Skip to content

Commit

Permalink
Implemented support for production nginx server
Browse files Browse the repository at this point in the history
  • Loading branch information
Waujito committed Apr 23, 2024
1 parent e2d0074 commit 2f783cb
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 7 deletions.
39 changes: 36 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
networks:
messenger:
ipv4_address: 10.5.1.3
env_file:
- .frontend.env
ports:
- 80:3000
working_dir: /frontend
Expand All @@ -34,9 +36,9 @@ services:
messenger:
ipv4_address: 10.5.1.10
ports:
- 8080:80
- 8090:80
env_file:
- ./api/.env
- .api.env
- .postgresql.env
depends_on:
- postgres
Expand All @@ -56,11 +58,24 @@ services:
- 443:443
- 47485:80
env_file:
- ./api/.env
- .api.env
- .postgresql.env
volumes:
- ./crt:/crt

frontend_prod:
build:
context: web_frontend
target: serve
args:
- apiURI=${PROD_API_URI}
- apiURL=${PROD_API_URL}
networks:
messenger:
ipv4_address: 10.5.1.12
ports:
- 3000:80

postgres:
image: postgres:16-alpine
restart: always
Expand Down Expand Up @@ -89,6 +104,24 @@ services:
ports:
- 8081:8080

nginx:
build:
context: nginx

deploy:
restart_policy:
condition: on-failure
delay: 3s
max_attempts: 5
window: 60s
networks:
messenger:
ipv4_address: 10.5.1.80

ports:
- 8080:80


volumes:
pgstorage:

Expand Down
5 changes: 5 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:1.25-alpine as serve

RUN rm -rf /etc/nginx
COPY ./conf /etc/nginx

99 changes: 99 additions & 0 deletions nginx/conf/mime.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;

text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;

image/avif avif;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;

font/woff woff;
font/woff2 woff2;

application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/wasm wasm;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;

application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;

audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;

video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}
46 changes: 46 additions & 0 deletions nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
user nginx;
worker_processes 4;

events {
worker_connections 1024;
}

http {
include mime.types;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream backend {
server 'api_uwsgi';
}

upstream frontend {
server 'frontend_prod';
}

server {
listen 80;
absolute_redirect off;

location /api { return 302 /api/; }
location /api/ {
proxy_pass http://backend/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

location /socket.io { return 302 /socket.io/; }
location /socket.io/ {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

location / {
proxy_pass http://frontend;
}
}
}
1 change: 1 addition & 0 deletions systemd-cat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asdf -t ms -p emerg
3 changes: 2 additions & 1 deletion web_frontend/.example.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NUXT_PUBLIC_API_URL=
NUXT_PUBLIC_API_URL=
NUXT_PUBLIC_API_URI=
4 changes: 4 additions & 0 deletions web_frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
FROM node:20-alpine as build
WORKDIR /app

ARG apiURI, apiURL
ENV NUXT_PUBLIC_API_URI $apiURI
ENV NUXT_PUBLIC_API_URL $apiURL

COPY ./package.json .
COPY ./yarn.lock .
RUN yarn install
Expand Down
4 changes: 4 additions & 0 deletions web_frontend/helpers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ export function baseURL() {
export function API_URL() {
return useRuntimeConfig().public.apiURL;
}

export function API_URI() {
return useRuntimeConfig().public.apiURI;
}
7 changes: 4 additions & 3 deletions web_frontend/helpers/messagingApi/chatSocket.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Socket, io } from "socket.io-client";
import { API_URL } from "../app";
import { API_URL, API_URI } from "../app";
import type { ReadyUser } from "~/types/user";

let socket: Socket | undefined;

function initSocket(user: ReadyUser) {
if (!socket)
socket = io(`${API_URL()}/chat`, {
if (!socket) {
socket = io(`${API_URI()}/chat`, {
auth: {
token: user.token.rawToken,
},
});
}

return socket;
}
Expand Down
1 change: 1 addition & 0 deletions web_frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineNuxtConfig({
runtimeConfig: {
public: {
apiURL: "",
apiURI: "",
},
},
});

0 comments on commit 2f783cb

Please sign in to comment.