Docker compose - combine angular and laravel - docker

I have a project with the following elements:
frontend - Angular
backend - Laravel
DB - AWS RDS
I want to make to dockerize this project locally and I have several questions:
Is it possible to have only 1 docker NGINX service which will work with frontend and backend without using volumes?
When I will write at enironment of angular the route for the backend, like: http://backend/api/login - should it work?
When I'm trying to open localhost:8050 - I can see the frontend part and the request can't reach the backend container. Please advice
What is the best practise in this case to use at cloud solutions: to use shared drive with 2 folders for frontend and backend and mount them at each container or something else?
Docker-compose
version: '3'
services:
nginx-frontend:
restart: always
build:
dockerfile: dockerfile
context: ./nginx
ports:
- '8050:80'
backend:
build:
dockerfile: dockerfile
context: ./backend
ports:
- '1000:80'
Nginx configuration
server {
listen 80;
# Log files for Debug
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
# Laravel web root directory
root /var/www/html/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
# Nginx Pass requests to PHP-FPM
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass backend:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Nginx-frontend dockerfile
FROM node:14.17.6 as build
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY ./frontend/code/package.json ./frontend/code/package-lock.json ./
RUN apt-get update || : && apt-get install python -y
RUN npm install node-sass -y
RUN npm rebuild node-sass
RUN npm install
COPY ./frontend/code .
RUN npm run build
FROM nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /usr/src/app/dist /var/www/html
Backend dockerfile
FROM php:7.4-fpm as php-build
RUN apt-get -y update
RUN apt-get -y install curl
RUN apt-get -y install zip
RUN apt-get -y install libzip-dev
RUN apt-get -y install libpng-dev
RUN docker-php-ext-install zip
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN docker-php-ext-configure gd && docker-php-ext-install gd
COPY ./code /var/www/html
WORKDIR /var/www/html
RUN composer require "ext-gd:*" --ignore-platform-reqs
RUN composer require phpoffice/phpspreadsheet --with-all-dependencies
RUN composer install
RUN chmod -R 777 /var/www/html/storage/
RUN chmod -R 777 /var/www/html/bootstrap/cache
FROM nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY --from=php-build /var/www/html /var/www/html
The configuration files are provided.

Related

How to pass environment variable to nginx.conf file in docker?

I am trying to setup ruby on rails with docker everything is good but i want dynamic domain pass as environment variable to nginx.conf file during build image by docker-compose command but i don't know how to do it.
i trying to use this command
Docker-compose build
dcoker-compose up
Docker File
FROM ruby:2.7.2
ENV RAILS_ROOT /var/www/quickcard
ENV BUNDLE_VERSION 2.1.4
ENV BUNDLE_PATH usr/local/bundle/gems
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_PORT 5000
COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y build-essential \
git \
libxml2-dev \
libpq-dev \
libxslt-dev \
nodejs \
yarn \
imagemagick \
tzdata \
less \
cron \
&& rm -rf /var/cache/apk/*
RUN gem install bundler --version "$BUNDLE_VERSION"
RUN mkdir -p $RAILS_ROOT
WORKDIR $RAILS_ROOT
ADD Gemfile Gemfile
ADD Gemfile.lock Gemfile.lock
COPY yarn.lock yarn.lock
RUN bundle install
EXPOSE $RAILS_PORT
RUN ln -s $RAILS_ROOT/config/systemd/puma.service /etc/systemd/system/quickcard
COPY . .
RUN crontab -l | { cat; echo ""; } | crontab -
RUN yarn install
RUN yarn install --check-files
RUN ls /var/www/quickcard/public
ENTRYPOINT ["entrypoint.sh"]
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
Nginx Docker File
FROM nginx
RUN apt-get update -qq && apt-get -y install apache2-utils
ENV RAILS_ROOT /var/www/quickcard
WORKDIR $RAILS_ROOT
RUN mkdir log
COPY public public/
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
COPY ./multi_quickcard.key /etc/nginx/multi_quickcard.key
COPY ./quickcard-ssl-test.pem /etc/nginx/quickcard-ssl-test.pem
EXPOSE 80 443
CMD [ "nginx", "-g", "daemon off;" ]
Nginx.conf e.g
upstream puma {
# Path to Puma SOCK file, as defined previously
server app:5000 fail_timeout=0;
}
server {
listen 80;
server_name default_server;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
location / {
root /var/www/quickcard/public/;
proxy_pass http://puma;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
location /api {
root /var/www/quickcard/public/;
proxy_pass http://puma;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
location ^~ /assets/ {
root /var/www/quickcard/public/;
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
Docker Compose File
version: '2.2'
services:
app:
build:
context: .
dockerfile: ./Dockerfile
command: bash -c "bundle exec rails s -p 5000 -e production -b 0.0.0.0 && RAILS_ENV=production bundle exec rake assets:precompile"
environment:
RAILS_ENV: production
volumes:
- /var/wwww/quickcard
- /var/wwww/quickcard/public
ports:
- 5000:5000
sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
environment:
RAILS_ENV: production
volumes:
- /var/wwww/quickcard/tmp
cron_job:
build: .
command: cron -f
nginx:
build:
context: .
dockerfile: ./nginx.Dockerfile
volumes:
- ./log-nginx:/var/log/nginx/
restart: always
ports:
- 80:80
- 443:443
nginx Docker image can extract environment variables before it starts, but it's a bit tricky. One solution is to:
Add env variables to your nginx.conf file.
Copy it to /etc/nginx/templates/nginx.conf.template in the container (as opposed to your normal /etc/nginx) in the build step or as a volume.
Set the NGINX_ENVSUBST_OUTPUT_DIR: /etc/nginx environment variable in docker-compose.yml.
This will cause the nginx.conf.template file to be copied to /etc/nginx as nginx.conf and the environment variables will be replaced with their values.
There is one caveat to keep in mind: using command property in docker-compose.yml seems to be disabling the extraction functionality. If you need to run a custom command to start-up nginx, you can use the Dockerfile version.
I created a repo with the full setup, but in case it's not available:
# docker-compose.yml
version: "3"
services:
nginx-no-dockerfile:
container_name: nginx-no-dockerfile
image: nginx:1.23.1-alpine
ports:
- 8081:80
volumes:
- ./site/index.html:/usr/share/nginx/html/index.html
- ./site/nginx.conf:/etc/nginx/templates/nginx.conf.template
working_dir: /usr/share/nginx/html
environment:
NGINX_ENVSUBST_OUTPUT_DIR: /etc/nginx
API_URL: http://example.com
nginx-with-dockerfile:
container_name: nginx-with-dockerfile
build:
context: ./site
dockerfile: ./Dockerfile
ports:
- 8082:80
volumes:
- ./site/index.html:/usr/share/nginx/html/index.html
environment:
NGINX_ENVSUBST_OUTPUT_DIR: /etc/nginx
API_URL: http://example.com
# site/nginx.conf
worker_processes auto;
events {
}
http {
include /etc/nginx/mime.types;
server {
listen 80;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location /example {
proxy_pass $API_URL;
}
}
}
# site/Dockerfile
FROM nginx:1.23.1-alpine
WORKDIR /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/templates/nginx.conf.template
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Run no Dockerfile version: docker compose up nginx-no-dockerfile
Run Dockerfile version:
docker compose build nginx-with-dockerfile
docker compose up nginx-with-dockerfile
Make sure to also have index.html file in the site folder.
The recommended approach Nginx seems to be to use the envsubst utility. You would need to create a template file with the variable placed inside as $Variable or {Variable}. You could then pass into envsubst the template file which would render the variable from the environment.
This has a few downsides in that it can potentially replace nginx variables unintentionally so I would make sure to pass in the specific variables you would want to replace.
See this question which addresses a similar problem for more details: https://serverfault.com/questions/577370/how-can-i-use-environment-variables-in-nginx-conf

How to run Nginx + SSL in docker?

This configuration was tested without docker. The site on SSL was launched without errors. Now when I want to run this server configuration in docker, I get no errors during installation, but the server does not start at all.
nginx.dockerfile
FROM nginx:stable-alpine
RUN mkdir -p /var/www/html
WORKDIR /var/www/html
RUN addgroup -g 1000 laravel && adduser -G laravel -g laravel -s /bin/sh -D laravel
RUN chown laravel:laravel /var/www/html
COPY ./nginx/ssl/mysite.ru/mysite_ru.crt /etc/nginx/ssl/mysite.ru/mysite_ru.crt
COPY ./nginx/ssl/mysite.ru/mysite_ru.key /etc/nginx/ssl/mysite.ru/mysite_ru.key
RUN apk update \
&& ln -sf ./nginx/ssl/mysite.ru /etc/nginx/ssl/mysite.ru
ADD ./nginx/nginx.conf /etc/nginx/nginx.conf
ADD ./nginx/default.conf /etc/nginx/conf.d/default.conf
the ./nginx/ssl/mysite_com folder contains working files: mysite_com. crt and mysite_com.key
This files checked without docker
docker-compose.yml
services:
site:
build:
context: .
dockerfile: nginx.dockerfile
container_name: nginx
ports:
- 80:80
- 443:443
volumes:
- ./src:/var/www/html:delegated
- ./nginx/ssl:/etc/nginx/ssl
depends_on:
- php
- mysql
- postgres
networks:
- laravel
default.conf
server {
listen 443 ssl;
server_name mysite.ru;
ssl_certificate /etc/nginx/ssl/mysite.ru/mysite_ru.crt;
ssl_certificate_key /etc/nginx/ssl/mysite.ru/mysite_ru.key;
index index.php index.html;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Tell me, what is the error?
and where can I view nginx logs in docker?
It seems you have not added or copied your SSL cert and key files to your nginx image.
Add COPY keyword before RUN apk update ... and then restart nginx at the end so that your Dockerfile looks like this and I think it should solves your problem:
FROM nginx:stable-alpine
RUN mkdir -p /var/www/html
WORKDIR /var/www/html
RUN addgroup -g 1000 laravel && adduser -G laravel -g laravel -s /bin/sh -D laravel
RUN chown laravel:laravel /var/www/html
COPY mysite_com.crt /etc/nginx/ssl/mysite.com/
COPY mysite_com.key /etc/nginx/ssl/mysite.com/
RUN apk update \
&& ln -sf ./nginx/ssl/mysite_com /etc/nginx/ssl
ADD ./nginx/nginx.conf /etc/nginx/nginx.conf
ADD ./nginx/default.conf /etc/nginx/conf.d/default.conf

Adding ssl certificate to dockerized app breaks api call

We have two docker containters. one running our angular app and one running our laravel api. Each has their own docker-compose file.
On our localhost there was no issue making api calls from angular to laravel over 127.0.0.1:3000
Then I took these containers and started them up on my Ubuntu server. Still no problem making calls over 195.xxx.xxx.xx:3000
I then added a ssl certificate to the domain and all of the sudden I can not make calls to the api over port 3000
Can anyone tell me where I am going wrong. I have tried different ports. If I remove the certbot stuff and call over http it all works fine again. Please please help...
For my ssl setup I followed this article and got it all setup without any real issues
Here is to docker setup for laravel
Dockerfile:
FROM php:7.3-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
mariadb-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
libzip-dev
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 3000 and start php-fpm server
EXPOSE 3000
CMD php-fpm
docker-compose.yml
version: "3"
services:
#PHP Service
api:
build:
context: .
dockerfile: Dockerfile
image: laravel360
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "3000:80"
- "3001:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: name
MYSQL_ROOT_PASSWORD: password
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Any finally the config file
server {
listen 80;
client_max_body_size 100M;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
server {
listen 443 ssl;
client_max_body_size 100M;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
Angular Docker
#############
### build ###
#############
# base image
FROM node:alpine as build
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install
RUN npm install -g #angular/cli#~9.1.0
# add app
COPY . /app
# run tests
# RUN ng test --watch=false
# RUN ng e2e --port 4202
# generate build
RUN ng build --output-path=dist
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80 443
CMD [ "nginx", "-g", "daemon off;" ]
Docker Compose
version: '3'
services:
angular:
container_name: angular
build:
context: .
dockerfile: Dockerfile-prod
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;'"
And then finally my nginx conf for the angular side
server {
listen 80;
server_name mydomaindotcom;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri /index.html;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
server {
listen 443 ssl;
server_name mydomaindotcom;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri /index.html
proxy_pass http://mydomaindotcom; #for demo purposes
proxy_set_header Host http://mydomaindotcom;
}
ssl_certificate /etc/letsencrypt/live/mydomaindotcom/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomaindotcom/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

Docker / Nginx / Symfony4: php modifications aren't displayed

I'm setting up a docker stack for a Symfony 4 application with Nginx and PHP 7. I need advice for my docker stack because i met one problem : every changes in a PHP file (a controller, a repository, an entity etc...) aren't displayed. Each time, i need to down ma docker stack and restart to see the changes, even for a simple dump().
I verified OPCache is enabled and configured like in Symfony documentation.
I think the problem is in my docker stack.
This is docker-compose.yml :
version: '2.2'
services:
# PHP
php:
build:
context: docker/php7-fpm
args:
TIMEZONE: ${TIMEZONE}
container_name: dso_php
volumes:
- ".:/var/www/myproject:rw,cached"
- "./docker/php7-fpm/www.conf:/usr/local/etc/php-fpm.d/www.conf"
- "./docker/php7-fpm/php.ini:/usr/local/etc/php/conf.d/030-custom.ini"
env_file:
- .env
working_dir: /var/www/myproject
# NGINX
nginx:
build:
context: docker/nginx
args:
NGINX_HOST: ${NGINX_HOST}
container_name: dso_nginx
ports:
- 80:80
depends_on:
- php
volumes:
- ".:/var/www/myproject:cached"
- ./logs/nginx/:/var/log/nginx
env_file:
- .env
environment:
- NGINX_HOST=${NGINX_HOST}
I build my own Dockerfile for PHP and Nginx:
First PHP, here the Dockerfile :
FROM php:7.2-fpm
MAINTAINER HamHamFonFon <balistik.fonfon#gmail.com>
USER root
# Utils
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y curl less vim libpq-dev wget gnupg libicu-dev libpng-dev zlib1g-dev sudo wget \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install intl \
&& docker-php-ext-install opcache \
&& docker-php-ext-install zip \
&& docker-php-ext-install gd
RUN apt-get install -y zip unzip
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& composer --version
# npm & node
RUN curl -sL https://deb.nodesource.com/setup_9.x | bash
RUN apt-get install -y nodejs npm \
&& update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
# build tools
RUN apt-get install -y build-essential
# yarn package manager
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# Git
RUN apt-get install -y git
# bugfix: remove cmdtest to install yarn correctly.
RUN apt-get remove -y cmdtest
RUN apt-get update
RUN apt-get install -y yarn
# Clear archives in apt cache folder
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
ENTRYPOINT ["docker-entrypoint"]
php.ini :
; General settings
date.timezone = Europe/Paris
xdebug.max_nesting_level=500
short_open_tag = Off
memory_limit="512M"
; Error reporting optimized for production (http://www.phptherightway.com/#error_reporting)
display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL
log_errors = On
error_log = /var/log/php-app/error.log
apc.enable_cli = 1
# http://symfony.com/doc/current/performance.html
opcache.interned_strings_buffer = 16
opcache.memory_consumption = 256
opcache.max_accelerated_files = 20000
opcache.validate_timestamps=0
; maximum memory allocated to store the results
realpath_cache_size=4096K
; save the results for 10 minutes (600 seconds)
realpath_cache_ttl=600
And www.conf (i have removed in this exemple all commented lines) :
[www]
user = site
listen = [::]:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php_admin_value[upload_max_filesize] = 50M
php_admin_value[post_max_size] = 50M
Now, for nginx :
First, Dockerfile :
FROM debian:jessie
ARG NGINX_HOST
MAINTAINER HamHamFonFon <balistik.fonfon#gmail.com>
# Install nginx
RUN apt-get update && apt-get install -y nginx
# Configure Nginx
ADD nginx.conf /etc/nginx/
ADD symfony.conf /etc/nginx/conf.d/
RUN sed "/server_name nginx_host;/c\ server_name ${NGINX_HOST};" -i /etc/nginx/conf.d/symfony.conf
RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf
RUN usermod -u 1000 www-data
# Run Nginx
CMD ["nginx"]
# Expose ports
EXPOSE 80
nginx.conf :
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
open_file_cache max=100;
client_body_temp_path /tmp 1 2;
client_body_buffer_size 256k;
client_body_in_file_only off;
}
daemon off;
And finally, symfony.conf :
server {
listen 80;
listen [::]:80;
server_name nginx_host;
client_max_body_size 20M;
root /var/www/deep-space-objects/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/(index)\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/symfony_error.log;
access_log /var/log/nginx/symfony_access.log;
}
In Dockerfile, the command "sed" replace "nginx_host" by the server name i declare in .env file.
My problem looks like this one : Docker with Symfony 4 - Unable to see the file changes but i have verified the OPCache configuration.
How can i check if nginx and php communicate ? Are there some badthings in my stack i can improve ?
Thank you, i don't know how to looking for.

Semantic media wiki in docker

I am trying to get the SMW running in a Docker container. I get the
main page up, but it will not let me log in. It says:
Login error
Knowledgebase uses cookies to log in users. You have cookies disabled.
Please enable them and try again.
My browser does have cookies enabled.
Anyone here run SMW in Docker and/or have a clue on how I can fix this issue?
Dockerfile:
FROM centos:centos7
ENV HOME /opt/smw
ADD . $HOME
RUN chmod 777 $HOME
# Add the ngix and PHP dependent repository
ADD nginx.repo /etc/yum.repos.d/nginx.repo
# Installing packages
RUN yum -y install nginx
# Installing PHP
RUN yum -y --enablerepo=remi,remi-php56 install nginx php-fpm php-common php-mysql php-xml
# Installing MySQL
RUN yum -y install wget && \
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm && \
rpm -ivh mysql-community-release-el7-5.noarch.rpm && \
yum -y update && \
yum -y install mysql-server
# Installing supervisor
RUN yum install -y python-setuptools
RUN easy_install pip
RUN pip install supervisor
# Adding the configuration file of the nginx
ADD nginx.conf /etc/nginx/nginx.conf
ADD default.conf /etc/nginx/conf.d/default.conf
# Adding the configuration file of the Supervisor
ADD supervisord.conf /etc/
# Config MySQL
RUN chmod 755 $HOME/config_mysql.sh
RUN $HOME/config_mysql.sh
VOLUME ["/opt/smw"]
VOLUME ["/var/lib/mysql"]
EXPOSE 80
CMD ["/opt/smw/run.sh"]
supervisord.conf:
[supervisord]
;logfile=/var/log/supervisor/supervisord-nobody.log ; (main log file;default $CWD/supervisord.log)
;logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
;logfile_backups=10 ; (num of main logfile rotation backups;default 10)
;loglevel=info ; (log level;default info; others: debug,warn,trace)
;pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
;user=nobody
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:php5-fpm]
command=/usr/sbin/php-fpm -c /etc/php-fpm.d
numprocs=1
autostart=true
autorestart=true
[program:php5-fpm-log]
command=tail -f /var/log/php5-fpm.log
stdout_events_enabled=true
stderr_events_enabled=true
[program:nginx]
command=/usr/sbin/nginx
numprocs=1
autostart=true
autorestart=true
nginx config:
server {
listen 80;
root /opt/smw;
index index.html index.htm index.php;
# Make site accessible from http://set-ip-address.xip.io
server_name localhost;
access_log /var/log/nginx/localhost.com-access.log;
error_log /var/log/nginx/localhost.com-error.log error;
charset utf-8;
location / {
try_files $uri $uri/ /index.html /index.php?$query_string;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Deny .htaccess file access
location ~ /\.ht {
deny all;
}
Instead of installing remi-php56 I installed just plain php and then I did not have the issue.

Resources