I'm working with containers in docker 
Where I have one from PHP-FPM and another from Nginx.
But I'm having problems with Nginx to serve the static files (css, js)
Return Status Code: 404 Not Found
server {
  # Set the port to listen on and the server name
  listen 80;
  listen [::]:80;
  # Set the document root of the project
  root /var/www/html;
  # Set the directory index files
  index index.php;
 #Set server name
 server_name myproject;
  # Specify the default character set
  charset utf-8;
  # Specify the logging configuration
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
  # Specify what happens when PHP files are requested
  location ~* \.php$ {
      #try_files $uri =404;
      #try_files /index.php = 404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass    myproject:9000;
      fastcgi_index   index.php;
      include         fastcgi_params;
      fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
      fastcgi_param   SCRIPT_NAME         $fastcgi_script_name;
      fastcgi_param   PATH_INFO           $fastcgi_path_info;
  }
  location / {
      index index.php;
      try_files $uri $uri/ /index.php;
      include /etc/nginx/mime.types;
  } 
  location ~* \.(jpg|jpeg|png|css|js|ico|xml)$ {
      access_log        off;
      log_not_found     off;
     expires           360d;
     add_header Cache-Control "public";
  }
  # Specify what happens what .ht files are requested
  location ~ /\.ht {
      deny all;
  }
}
FROM php:7-fpm
RUN docker-php-ext-install pdo_mysql 
COPY . /var/www/html/
EXPOSE 9000
FROM nginx:1.12.2
COPY ./default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
                Serving Static Files To deploy the container, use Docker Compose. The Docker Compose output. Your static folder and all of its contents are now being served at http://localhost:8080/ using Nginx running inside Docker. Our static files being served on port 8080.
Configure NGINX and NGINX Plus to serve static content, with type-specific root directories, checks for file existence, and performance optimizations.
After the restart, PHP is fully enabled on Nginx. To prove this, create a PHP file in Nginx's /var/www/html folder and test to ensure the page renders properly on the server.
I think the problem, cause service nginx can not find your web project. If you use docker-compose you can use volume, but if not you can add folder project in nginx Dockerfile to /var/www/html
ROM nginx:1.12.2
COPY . /var/www/html/
COPY ./default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
services:
  nginx:
    images: nginx:latest
    ...
    ...
    volumes:
           - ./:/var/www/html
  php:
    images: php
    ...
    ...
    volumes:
           - ./:/var/www/html
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With