nginx 1.14.2 docker bad gateway respone - docker

Good day.
I have been working with Docker recently. Faced such a problem:
The administrative part of the site is working fine, and the public part gives an error 502 bad gateway.
Here are the settings for my docker:
docker-kompose.yml (root folder):
version: '3'
services:
nginx:
image: nginx:1.14
ports:
- "${NGINX_HOST}:${NGINX_PORT}:80"
volumes:
- ./:/var/www/html:cached
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
depends_on: [php]
env_file: .env
restart: always
php:
build:
context: docker/php
args:
TIMEZONE: ${TIMEZONE}
volumes:
- ./:/var/www/html:cached
- ./docker/php/php.ini:/usr/local/etc/php/php.ini:cached
- ./docker/php/php-fpm.conf:/usr/local/etc/php-fpm.d/99-custom.conf:cached
user: "${DOCKER_UID}"
env_file: .env
restart: always
docker-kompose.override.yml (root folder):
version: '3'
services:
markup:
build: docker/markup
user: "${DOCKER_UID}"
ports:
- "${MARKUP_PORT}:4000"
volumes:
- ./:/app:cached
command: bash -c "npm install --no-save && bower install && gulp external"
environment:
NODE_ENV: "${MARKUP_ENV}"
.env file (root folder):
COMPOSE_PROJECT_NAME=nrd
# "docker-compose.yml:docker-compose.prod.yml" for prod
# "docker-compose.yml:docker-compose.stage.yml" for stage
COMPOSE_FILE=
DOCKER_UID=1000
DOCKER_ADDRESS=172.17.0.1
# "develop" or "production"
MARKUP_ENV=develop
MARKUP_PORT=4000
# 0.0.0.0 for external access
NGINX_HOST=127.0.0.1
NGINX_PORT=80
TIMEZONE=Europe/Moscow
nginx.conf (folder docker/nginx/):
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log off;
error_log /dev/null crit;
client_max_body_size 1024M;
client_header_buffer_size 4k;
large_client_header_buffers 4 8k;
sendfile on;
keepalive_timeout 65;
map $http_x_forwarded_proto $fastcgi_https {
default off;
https on;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
root /var/www/html;
listen 80;
server_name _;
access_log off;
error_log /dev/null crit;
charset utf-8;
location ~ ^/(\.git|log|docker|\.env) {
return 404;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_read_timeout 7200;
fastcgi_send_timeout 72000;
fastcgi_buffer_size 32k;
fastcgi_buffers 16 32k;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS $fastcgi_https if_not_empty;
fastcgi_param REMOTE_ADDR $http_x_forwarded_for;
include fastcgi_params;
if (!-f $request_filename) {
rewrite ^(.*)/index.php$ $1/ redirect;
}
}
location / {
index index.php index.html index.htm;
if (!-e $request_filename){
rewrite ^(.*)$ /bitrix/urlrewrite.php last;
}
}
location ~ /\.ht {
deny all;
}
location ~* ^.+\.(xml|html|jpg|jpeg|gif|ttf|eot|swf|svg|png|ico|mp3|css|woff2?|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|dat|avi|ppt|txt|tar|mid|midi|wav|bmp|rtf|wmv|mpeg|mpg|mp4|m4a|spx|ogx|ogv|oga|webm|weba|ogg|tbz|js)$ {
expires 30d;
access_log off;
}
}
}
.Dockerfile (folder docker/php):
# See https://github.com/docker-library/php/blob/master/7.1/fpm/Dockerfile
FROM php:7.1-fpm
ARG TIMEZONE
RUN apt-get update && apt-get install -y \
openssl \
git \
zlibc \
zlib1g \
zlib1g-dev \
libfreetype6-dev \
libssl-dev \
libjpeg62-turbo-dev \
libmemcached-dev \
libmagickwand-dev \
libmcrypt-dev \
libpng-dev \
libicu-dev \
unzip
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN mkdir /.composer/ && chmod 777 /.composer/
# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"
# Type docker-php-ext-install to see available extensions
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install pdo_mysql gd
# Install memcached extension
RUN apt-get update \
&& apt-get install -y libmemcached11 libmemcachedutil2 build-essential libmemcached-dev libz-dev \
&& pecl install memcached \
&& echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini \
&& apt-get remove -y build-essential libmemcached-dev libz-dev \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /tmp/pear
RUN docker-php-ext-install intl
RUN docker-php-ext-install opcache
RUN docker-php-ext-install soap
RUN apt-get install -y --no-install-recommends default-libmysqlclient-dev
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip
RUN docker-php-ext-install mysqli
WORKDIR /var/www/html
CMD ["php-fpm"]
php.ini (folder docker/php):
[PHP]
short_open_tag = On
upload_max_filesize = 200M
post_max_size = 250M
display_errors = Off
memory_limit = 1024M
max_execution_time = 60
[mbstring]
mbstring.internal_encoding = UTF-8
mbstring.func_overload = 2
php-fpm.conf (folder docker/php):
[www]
pm = dynamic
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 10
access.format = "%{REMOTE_ADDR}e - %u %t \"%m %{REQUEST_URI}e%Q%q\" %s %{miliseconds}dms %{megabytes}MM %C%%"
;slowlog = /proc/self/fd/2
;request_slowlog_timeout = 2s
php_admin_value[error_log] = /proc/self/fd/2
php_admin_flag[log_errors] = on
.Dockerfile (folder docker/markup):
FROM node:10.13
RUN npm install -g gulp bower
RUN echo '{ "allow_root": true }' > /root/.bowerrc
RUN mkdir /.npm && mkdir /.config && mkdir /.cache && mkdir /.local && chmod 777 /.npm && chmod 777 /.config && chmod 777 /.cache && chmod 777 /.local
EXPOSE 4000
WORKDIR /app/markup
Please help, I do not understand what is the matter. Today everything worked fine, I did not touch the settings anywhere, I did not change the passwords anywhere. The public part of my local project just started giving 502 errors
Using Docker for Windows.

Related

Docker link to connect nginx and php containers

I tried to learn a (even though a bit outdated) form of linking containers. I created an NGINX and PHP container, which should get linked. Everything runs on my local machine.
Dockerfile NGINX
FROM ubuntu:16.04
MAINTAINER Sebastian Scharf
# Install NGINX
RUN apt-get update && apt-get install -y nginx \
# Clean after apt-get
&& apt-get clean \
## remove content from apt/lists and var/tmp
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
## set deamon off
&& echo "daemon off;" >> /etc/nginx/nginx.conf
ADD default /etc/nginx/sites-available/default
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
CMD ["nginx"]
Dockerfile PHP
FROM ubuntu:16.04
MAINTAINER Sebastian Scharf
RUN apt-get update \
&& apt-get install -y locales \
&& locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN apt-get update \
&& apt-get install -y curl zip unzip git software-properties-common \
&& add-apt-repository -y ppa:ondrej/php \
&& apt-get update \
&& apt-get install -y php7.0-fpm php7.0-cli php7.0-mcrypt php7.0-gd php7.0-mysql \
php7.0-pgsql php7.0-imap php-memcached php7.0-mbstring php7.0-xml php7.0-curl \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& mkdir /run/php \
&& apt-get remove -y --purge software-properties-common \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ADD php-fpm.conf /etc/php/7.0/fpm/php-fpm.conf
ADD www.conf /etc/php/7.0/fpm/pool.d/www.conf
EXPOSE 9000
CMD ["php-fpm7.0"]
NGINX CONFIG
server {
listen 8080 default_server;
root /var/www/html/public;
index index.html index.htm index.php;
server_name _;
charset utf-8;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass php:9000;
}
error_page 404 /index.php;
location ~ /\.ht {
deny all;
}
}
When I call localhost:8080, I get the error: This page isn't working (localhost didn't send any data). I was expecting to see a test file.
This is how I started the containers and linked them:
docker run -d --name=myphp -v $(pwd)/application:/var/www/html retronexus/php:0.1.0
docker run -d --link=myphp:php -p 8080:80 -v $(pwd)/application:/var/www/html retronexus/nginx:0.2.0
Nginx in your container listens on port 8080, but you are binding port 80 from the container to 8080 on the host. Switch to binding 8080 from the container.
docker run -d \
--link=myphp:php \
-p 8080:8080 \
-v $(pwd)/application:/var/www/html \
retronexus/nginx:0.2.0
See here for more details: https://docs.docker.com/config/containers/container-networking/#published-ports

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.

GET http://backend/api/countries net::ERR_NAME_NOT_RESOLVED

I am actually getting error when making CORS calls to the backend:
GET http://backend/api/countries net::ERR_NAME_NOT_RESOLVED
I am using for that docker-compose:
docker-compose.yml
version: '2'
networks:
minn_net:
services:
backend:
build: backend-symfony
container_name: backend
networks:
- minn_net
ports:
- 81:80
volumes:
- ./backend-symfony/backend/var/logs-nginx:/var/log/nginx
- ./backend-symfony/backend/:/var/www/html
- ./backend-symfony/errors/:/var/www/errors
db:
image: mysql:5.7.19
container_name: db
networks:
- minn_net
ports:
- 3306
volumes:
- "./.data/db:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
phpmyadmin:
image: phpmyadmin/phpmyadmin:edge-4.7
container_name: phpmyadmin
networks:
- minn_net
ports:
- 8080:80
links:
- db
frontend:
build: frontend-angular
container_name: frontend
networks:
- minn_net
links:
- backend # I added links as extra: may be the frontend recognises the backend
ports:
- 88:80
volumes:
- ./frontend-angular/frontend2/dist:/var/www/frontend
- ./frontend-angular/conf/docker/default.conf:/etc/nginx/conf.d/default.conf
- ./frontend-angular/logs/nginx/:/var/log/nginx
config of nginx for the backend
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
root /var/www/html/public;
index index.php;
# Make site accessible from http://localhost/
server_name _;
# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
sendfile off;
# Add stdout logging
error_log /dev/stdout info;
access_log /dev/stdout;
# Add option for x-forward-for (real ip when behind elb)
#real_ip_header X-Forwarded-For;
#set_real_ip_from 172.16.0.0/12;
location / {
# Match host using a hostname if you like
#if ($http_origin ~* (https?://.*\.tarunlalwani\.com(:[0-9]+)?$)) {
# set $cors "1";
#}
set $cors "1";
# OPTIONS indicates a CORS pre-flight request
if ($request_method = 'OPTIONS') {
set $cors "${cors}o";
}
# OPTIONS (pre-flight) request from allowed
# CORS domain. return response directly
if ($cors = "1o") {
add_header 'Access-Control-Allow-Origin' '$http_origin' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Lang, Authorization' always;
add_header Content-Length 0;
add_header Content-Type text/plain;
return 204;
}
add_header 'Access-Control-Allow-Headers' 'Content-Type,Authorization,Lang';
# add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' 'POST,GET,PUT,DELETE,OPTIONS';
add_header 'Access-Control-Allow-Origin' '*';
try_files $uri /index.php$is_args$args;
}
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html|eof|woff|ttf)$ {
add_header 'Access-Control-Allow-Headers' 'Content-Type,Authorization,Lang';
#add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' 'POST,GET,PUT,DELETE,OPTIONS';
add_header 'Access-Control-Allow-Origin' '*';
if (-f $request_filename) {
expires 30d;
access_log off;
}
}
location ~ \.php$ {
add_header 'Access-Control-Allow-Headers' 'Content-Type,Authorization,Lang';
#add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' 'POST,GET,PUT,DELETE,OPTIONS';
add_header 'Access-Control-Allow-Origin' '*';
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Angular service that calls the backend
import { Injectable } from '#angular/core';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '#angular/common/http';
// import { HttpClientModule } from '#angular/common/http';
// Grab everything with import 'rxjs/Rx';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw';
import { Observer } from 'rxjs/Observer';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import * as _ from 'lodash';
import { ICountry } from '#app/shared/interfaces';
#Injectable()
export class DataService {
baseUrl = 'http://backend/api'; // it does not work
// baseUrl = 'http://172.18.0.4/api'; // it works perfectly
constructor(private http: HttpClient) { }
// private httpheadersGet = new HttpHeaders().set("Access-Control-Allow-Origin", "http://localhost:4200");
public getCountries(): Observable<ICountry[]> {
return (
this.http
.get<ICountry[]>(this.baseUrl + '/countries'/* , {"headers": this.httpheadersGet} */)
.do(console.log)
.map(data => _.values(data["hydra:member"]))
.catch(this.handleError)
);
}
}
Please be noticed, if I set backend IP address manually from the frontend (as it can be seen in the angular code), the CORS calls are working perfectly. So, have I missing something in the config of the docker-compose.yml file?
PS: Even the network and the container names were specified to avoid an incorrect container name in the angular code.
Nginx Dockerfile for the frontend container
FROM debian:stretch-slim
LABEL maintainer="NGINX Docker Maintainers <docker-maint#nginx.com>"
ENV NGINX_VERSION 1.13.9-1~stretch
ENV NJS_VERSION 1.13.9.0.1.15-1~stretch
RUN set -x \
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y gnupg1 apt-transport-https ca-certificates \
&& \
NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \
found=''; \
for server in \
ha.pool.sks-keyservers.net \
hkp://keyserver.ubuntu.com:80 \
hkp://p80.pool.sks-keyservers.net:80 \
pgp.mit.edu \
; do \
echo "Fetching GPG key $NGINX_GPGKEY from $server"; \
apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \
done; \
test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \
apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \
&& dpkgArch="$(dpkg --print-architecture)" \
&& nginxPackages=" \
nginx=${NGINX_VERSION} \
nginx-module-xslt=${NGINX_VERSION} \
nginx-module-geoip=${NGINX_VERSION} \
nginx-module-image-filter=${NGINX_VERSION} \
nginx-module-njs=${NJS_VERSION} \
" \
&& case "$dpkgArch" in \
amd64|i386) \
# arches officialy built by upstream
echo "deb https://nginx.org/packages/mainline/debian/ stretch nginx" >> /etc/apt/sources.list.d/nginx.list \
&& apt-get update \
;; \
*) \
# we're on an architecture upstream doesn't officially build for
# let's build binaries from the published source packages
echo "deb-src https://nginx.org/packages/mainline/debian/ stretch nginx" >> /etc/apt/sources.list.d/nginx.list \
\
# new directory for storing sources and .deb files
&& tempDir="$(mktemp -d)" \
&& chmod 777 "$tempDir" \
# (777 to ensure APT's "_apt" user can access it too)
\
# save list of currently-installed packages so build dependencies can be cleanly removed later
&& savedAptMark="$(apt-mark showmanual)" \
\
# build .deb files from upstream's source packages (which are verified by apt-get)
&& apt-get update \
&& apt-get build-dep -y $nginxPackages \
&& ( \
cd "$tempDir" \
&& DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \
apt-get source --compile $nginxPackages \
) \
# we don't remove APT lists here because they get re-downloaded and removed later
\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
&& apt-mark showmanual | xargs apt-mark auto > /dev/null \
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
\
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
&& ls -lAFh "$tempDir" \
&& ( cd "$tempDir" && dpkg-scanpackages . > Packages ) \
&& grep '^Package: ' "$tempDir/Packages" \
&& echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list \
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
# ...
# E: Failed to fetch store:/var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
&& apt-get -o Acquire::GzipIndexes=false update \
;; \
esac \
\
&& apt-get install --no-install-recommends --no-install-suggests -y \
$nginxPackages \
gettext-base \
&& apt-get remove --purge --auto-remove -y apt-transport-https ca-certificates && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \
\
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
&& if [ -n "$tempDir" ]; then \
apt-get purge -y --auto-remove \
&& rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
fi
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["nginx", "-g", "daemon off;"]
After installing dnsutils
root#123e38093010:/# nslookup backend
Server: 127.0.0.11
Address: 127.0.0.11#53
Non-authoritative answer:
Name: backend
Address: 172.18.0.3

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.

Installing GeoIP module for latest NGINX for Docker

I am trying to create a docker image which contains a nginx service with GeoIP module. As far as I tried, running apt-get install nginx with any flags doesn't help to include the --with-http_geoip_module module in the nginx installed. Therefore, I tried to installed it from the nginx source
add-apt-repository ppa:nginx/development -y \
&& echo "deb-src http://ppa.launchpad.net/nginx/development/ubuntu xenial main" >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get build-dep nginx -y \
&& cd /opt \
&& mkdir tempnginx \
&& cd tempnginx \
&& apt-get source nginx \
and so on and so on
The GeoIP doesn't work as it should, as I tried to put it on the log as like this :
nginx.conf
user www-data;
worker_processes 1;
load_module modules/ngx_http_geoip_module.so;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
geoip_country /usr/share/GeoIP/GeoIP.dat;
geoip_city /usr/share/GeoIP/GeoLiteCity.dat;
log_format main '$remote_addr - [$time_local] '
'"$request" $status $bytes_sent $request_time $upstream_response_time'
'"$http_referer" "$http_user_agent" "$gzip_ratio" '
'"$geoip_region" "$geoip_city" "$geoip_city_country_code"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
}
The log will just print those GeoIP parameters as "-"
Any idea why it doesn't work? The Nginx version should be the latest one.
-- edit --
Add the result from running nginx -V
nginx version: nginx/1.13.3
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-mail=dynamic --with-mail_ssl_module --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/nginx-auth-pam --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/nginx-dav-ext-module --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/nginx-echo --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/nginx-upstream-fair --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/ngx_http_substitutions_filter_module
modules
modules
path=/usr/lib/nginx/modules
http_ssl_module
http_stub_status_module
http_realip_module
http_auth_request_module
http_v2_module
http_dav_module
http_slice_module
http_addition_module
http_geoip_module
http_gunzip_module
http_gzip_static_module
http_image_filter_module=dynamic
http_sub_module
http_xslt_module=dynamic
stream_ssl_module
stream_ssl_preread_module
mail_ssl_module
module=/opt/tempnginx/nginx
1.13.3/debian/modules/nginx
module=/opt/tempnginx/nginx
1.13.3/debian/modules/nginx
module
module=/opt/tempnginx/nginx
1.13.3/debian/modules/nginx
module=/opt/tempnginx/nginx
1.13.3/debian/modules/nginx
module=/opt/tempnginx/nginx
1.13.3/debian/modules/ngx_http_substitutions_filter_module
It turned out that the installation is working, and I just realised that I tried to access it from localhost, which means the IP becomes unresolved. After trying on remote host, the GeoIP module works fine :)

Resources