I am making this wordpress solution and for "dieting" reasons I am moving into alpine-based images.
On this I managed to use an external configuration (file) and via volume I pass it into nginx.
server {
listen 80;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ .php{
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_intercept_errors on;
}
}
But when I try to visit it on a browser by giving http://localhost:8080 (where I map the port 80 it into my docker-compose.yml):
version: '2'
services:
nginx:
image: nginx:alpine
ports:
- "8080:80"
volumes:
- './conf/nginx/:/etc/nginx/conf.d/:ro'
links:
- "wordpress"
volumes_from:
- "wordpress:ro"
wordpress-db:
image: mariadb
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "wordpress"
MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
wordpress:
build:
context: .
dockerfile: Dockerfile
image: ellakcy/wordpressswithplugins:alpine
links:
- wordpress-db
environment:
WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
WORDPRESS_URL: '${WORDPRESS_URL}'
But for some reason seems that redirects to port 80.
Also when I run via docker-compose up
command I get the following piece of log:
wordpress_1 | 172.23.0.4 - 18/Aug/2017:12:36:57 +0000 "GET /index.php" 301
nginx_1 | 172.23.0.1 - - [18/Aug/2017:12:36:57 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
wordpress_1 | 172.23.0.4 - 18/Aug/2017:12:41:22 +0000 "GET /index.php" 301
nginx_1 | 172.23.0.1 - - [18/Aug/2017:12:41:22 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
So I guess for some reason the nginx performs a 301 redirect to port 80. Do you have any Idea why that happens?
Edit 1
I also tried to set the 8080 port into the nginx configuration too:
Nginx configuration:
server {
listen 8080;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ .php{
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_intercept_errors on;
}
}
docker-compose.yml:
version: '2' services: nginx: image: nginx:alpine ports: - "8080:8080" volumes: - './conf/nginx/:/etc/nginx/conf.d/:ro' links: - "wordpress" volumes_from: - "wordpress:ro"
wordpress-db:
image: mariadb
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "wordpress"
MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
wordpress:
build:
context: .
dockerfile: Dockerfile
image: ellakcy/wordpressswithplugins:alpine
links:
- wordpress-db
environment:
WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
WORDPRESS_URL: '${WORDPRESS_URL}'
I still get the same behaviour
I am making this wordpress solution and for "dieting" reasons I am moving into alpine-based images.
On this I managed to use an external configuration (file) and via volume I pass it into nginx.
server {
listen 80;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ .php{
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_intercept_errors on;
}
}
But when I try to visit it on a browser by giving http://localhost:8080 (where I map the port 80 it into my docker-compose.yml):
version: '2'
services:
nginx:
image: nginx:alpine
ports:
- "8080:80"
volumes:
- './conf/nginx/:/etc/nginx/conf.d/:ro'
links:
- "wordpress"
volumes_from:
- "wordpress:ro"
wordpress-db:
image: mariadb
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "wordpress"
MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
wordpress:
build:
context: .
dockerfile: Dockerfile
image: ellakcy/wordpressswithplugins:alpine
links:
- wordpress-db
environment:
WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
WORDPRESS_URL: '${WORDPRESS_URL}'
But for some reason seems that redirects to port 80.
Also when I run via docker-compose up
command I get the following piece of log:
wordpress_1 | 172.23.0.4 - 18/Aug/2017:12:36:57 +0000 "GET /index.php" 301
nginx_1 | 172.23.0.1 - - [18/Aug/2017:12:36:57 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
wordpress_1 | 172.23.0.4 - 18/Aug/2017:12:41:22 +0000 "GET /index.php" 301
nginx_1 | 172.23.0.1 - - [18/Aug/2017:12:41:22 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
So I guess for some reason the nginx performs a 301 redirect to port 80. Do you have any Idea why that happens?
Edit 1
I also tried to set the 8080 port into the nginx configuration too:
Nginx configuration:
server {
listen 8080;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ .php{
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_intercept_errors on;
}
}
docker-compose.yml:
version: '2'
services:
nginx:
image: nginx:alpine
ports:
- "8080:8080"
volumes:
- './conf/nginx/:/etc/nginx/conf.d/:ro'
links:
- "wordpress"
volumes_from:
- "wordpress:ro"
wordpress-db:
image: mariadb
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "wordpress"
MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
wordpress:
build:
context: .
dockerfile: Dockerfile
image: ellakcy/wordpressswithplugins:alpine
links:
- wordpress-db
environment:
WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
WORDPRESS_URL: '${WORDPRESS_URL}'
I still get the same behaviour.
Edit 2
I also tried to use the following nginx settings (fot the nginx container)
server {
listen 8080;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ .php {
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_intercept_errors on;
}
}
And still I see no light in my path.