Answer the question
In order to leave comments, you need to log in
How to correctly specify the path to the project in the nginx config?
I'm trying to shove a Laravel project into the docker, I created all the necessary containers, each of which docker-compose up
issues "ready to accept connection"
. But when I try to connect directly through the browser, I get an error 404 page not found
. As far as I understand, it cannot find the index.php file in public/ and as far as I understand, this is due to the nginx container. Here are mine:
Docker-compose.yml (which is in the project, inside the _docker folder)
nginx:
build:
context: docker/nginx
container_name: ${COMPOSE_PROJECT_NAME}.nginx
networks:
- frontend
- backend
env_file:
- application.env
restart: unless-stopped
depends_on:
- php-fpm
volumes:
- ../:/app/
- ./docker/nginx/sites/:/etc/nginx/sites-available/
FROM nginx:alpine
ADD nginx.conf /etc/nginx/
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& adduser -D -H -u 1000 -s /bin/bash -Gwww-data www-data
CMD ["nginx"]
EXPOSE 80
upstream php-upstream {
server php-fpm:9000;
}
server {
charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name _;
root /app/public;
index index.php;
access_log /dev/stdout;
error_log /dev/sterr;
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|eot|ttf|otf|woff|woff2|svg)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
add_header Access-Control-Allow-Origin *;
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
rewrite ^/index.php(?:/)(.*)$ /$1 permanent;
# rewrite ^/index.php$ / permanent;
if ($request_uri ~* "^/index\.php$") {
return 301 /;
}
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# uncomment to avoid processing of calls to non-existing static files by Yii
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
# try_files $uri =404;
#}
#error_page 404 /404.html;
# deny accessing php files for the /assets directory
location ~ ^/assets/.*\.php$ {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-upstream;
try_files $uri =404;
}
location ~* /\. {
deny all;
}
}
Answer the question
In order to leave comments, you need to log in
- ./docker/nginx/sites/:/etc/nginx/sites-available/
docker run --rm -it nginx:alpine ls -1 /etc/nginx
conf.d
fastcgi.conf
fastcgi_params
mime.types
modules
nginx.conf
scgi_params
uwsgi_params
docker run --rm -it nginx:alpine ls -1 /etc/nginx/conf.d/
default.conf
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question