Last active
November 3, 2020 15:04
-
-
Save racinmat/aea35b4cff3ac5e350dddf24ca48f08c to your computer and use it in GitHub Desktop.
Simple setup of nginx+node.js+php app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stages: | |
- build | |
build_php: | |
<<: *build_definition | |
script: | |
- "docker build --pull -f php_app_Dockerfile -t <php image> --no-cache ." | |
- "docker push <php image>" | |
build_nginx: | |
<<: *build_definition | |
script: | |
- "docker build --pull -f nginx_app_Dockerfile -t <nginx image> --no-cache ." | |
- "docker push <nginx image>" | |
build_node: | |
<<: *build_definition | |
script: | |
- "docker build --pull -f ./docker/node_app/Dockerfile -t <node image> --no-cache ." | |
- "docker push <node image>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream php-upstream { | |
server php-fpm:9000; | |
} | |
upstream nodejs-upstream { | |
server node:3000; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
php-fpm: | |
image: php-app-prod | |
# + nějaké volumes, není důležité | |
links: | |
- redis | |
- database | |
nginx: | |
image: nginx-app-prod | |
ports: | |
- 80:80 | |
- 443:443 | |
restart: always | |
depends_on: | |
- php-fpm | |
adminer: | |
image: adminer | |
depends_on: | |
- database | |
ports: | |
- 8080:8080 | |
database: | |
restart: always | |
image: postgres | |
# nějaké env vars a volume, není důležité | |
ports: | |
- 5432:5432 | |
redis: | |
restart: always | |
image: redis | |
# nějaké env vars a volume, není důležité | |
ports: | |
- 6379:6379 | |
node: | |
depends_on: | |
- php-fpm | |
image: node-app-prod | |
ports: | |
- 3000:3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM nginx:1.19-alpine | |
ADD conf.d_default.conf /etc/nginx/conf.d/default.conf | |
ADD ./sites_default.conf /etc/nginx/sites-available/default.conf | |
ADD ./nginx.conf /etc/nginx/nginx.conf | |
CMD ["nginx"] | |
EXPOSE 80 443 | |
# kvůli index.php apod. | |
ADD ./www /var/www/public/www |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:14.15-buster | |
RUN npm install -g npm@latest | |
EXPOSE 3000 | |
COPY . /usr/src/app | |
# ve frontend složce jsou všechny react a node related věci | |
WORKDIR /usr/src/app/frontend | |
ENV PATH /usr/src/app/frontend/node_modules/.bin:$PATH | |
RUN npm install | |
ENV NODE_ENV production | |
CMD ["/usr/src/app/bin/node_init.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
npm run build --production | |
node_modules/.bin/next start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
server_name <server name>; | |
root /var/www/public/www/; | |
index index.php index.html index.htm; | |
location / { | |
try_files $uri @nodejs; | |
} | |
location @nodejs { | |
proxy_redirect off; | |
proxy_http_version 1.1; | |
proxy_pass http://nodejs-upstream; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
proxy_set_header Host $host ; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Host $server_name; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
} | |
location /api { | |
try_files $uri $uri/ /index.php$is_args$args; | |
} | |
location /nette { | |
try_files $uri $uri/ /index.php$is_args$args; | |
} | |
location ~ \.php$ { | |
try_files $uri /index.php =404; | |
fastcgi_pass php-upstream; | |
fastcgi_index index.php; | |
fastcgi_buffers 16 16k; | |
fastcgi_buffer_size 32k; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
#fixes timeouts | |
fastcgi_read_timeout 600; | |
include fastcgi_params; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
location ~ /\.|^\. { | |
deny all; | |
} | |
# cache static files | |
location ~* \.(jpe?g|gif|png|css|js|ico|xml)$ { | |
# passing the rest to nodejs | |
try_files $uri @nodejs; | |
access_log off; | |
log_not_found off; | |
expires max; | |
} | |
# cache static next.js data files, for some reason url is_next | |
# maybe it's not needed at all, hard to say | |
location ~* ^/_next/.*\.json$ { | |
# passing the rest to nodejs | |
try_files $uri @nodejs; | |
access_log off; | |
log_not_found off; | |
expires max; | |
} | |
# allow server-side includes for combined files | |
location ~ \.combined\.(js|css)$ { | |
ssi on; | |
ssi_types text/css text/javascript application/x-javascript; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment