Skip to content
Advertisement

Nginx on Docker serves only welcome pages

I’m using macOS. I’m working on a Debian image created through Dockerfile. Nginx, php-fpm was installed in Debian image. Then I copied server file to /etc/nginx/sites-available/server and created its symbolic link file in /etc/nginx/sites-enabled/. It also copied srcs/info.php files to /var/www/server/info.php. After starting nginx service, I can access my private IP address 192.168.0.46 and see NGINX’s welcome page. However, when accessing 192.168.0.46/info.php, page opening fails. This is the same when other html files are inserted.

I looked it up on Google and found out that it was an INCLUDE problem of /etc/nginx/nginx.conf, but there was no problem.

The first question I suspected was the firewall, but if it was the problem, shouldn’t I not be able to see the welcome page of Nginx? I’ve been thinking and searching all day, but I couldn’t get an answer. Please help me!

Here is my files:

Dockerfile :

FROM debian:buster

ARG DEBIAN_FRONTEND=noninteractive
ENV USER=root

COPY srcs/server.sites-available /etc/nginx/sites-available/server
COPY srcs/info.php /var/www/server/info.php
COPY srcs/login_form.html /var/www/server/login_form.html

# Installed mariadb-server instead of mysql-server

RUN apt-get update && apt-get upgrade -y && 
    apt-get install -y --no-install-recommends --no-install-suggests 
        nginx 
        openssl 
        mariadb-server 
        php-fpm 
        php-mysql && 
    ln -s /etc/nginx/sites-available/server /etc/nginx/sites-enabled/

CMD service mysql start; 
    service nginx start; 
    bash;

# EXPOSE 80 for HTTP and 443 for HTTPS
EXPOSE 80 443

server.sites-available :

server {
    listen 80;
    listen [::]:80;

    root /var/www/server;
    index index.php index.html index.htm;

    server_name server;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    }
}

info.php :

<?php
phpinfo();
?>

nginx.conf :

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

Here is my commands:

$ docker build -t server_image .
$ docker run -it -P --rm --name server_container server_image

Advertisement

Answer

use docker run -it -p 80:80 --rm --name server_container server_image to fix it. But I don’t know why…

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement