IT/Docker

docker php-nginx 404 에러

월공 2023. 12. 10. 11:34
728x90
300x250

docker 를 또 간만에 사용하게되어서 윈도우 도커에 php-nginx 이미지를 다운받고 가동시켰는데 404 에러가 떴다.

보통 docker 를 사용하지않고 그냥 로컬에서 nginx 를 깔게되면 아마 /etc/share/nginx/nginx.conf 여기에 모든 설정이 다 있을텐데 docker 로 돌렸을 경우에 conf 파일이 여기저기 찢어져있다.
여튼 conf 에 설정되있는 경로와 php 및 html 파일들이 없어서 나오는 에러다.

도커로 돌렸을 경우 우리가 흔히 생각하는 nginx.conf 파일은 /opt/docker/etc/ngnix 폴더 아래에 있다.

 # vi /opt/docker/etc/nginx/vhost.conf 
 
 server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name  _ *.vm docker;

    #root "/app";
    root  /var/www/html/[경로];

    #index index.php;

    include /opt/docker/etc/nginx/vhost.common.d/*.conf;
}

처음 컨테이너 가동 시켰을 경우에 root 가 /app 폴더로 되어있어서 404 에러가 떳던거고 저 부분 잘 고쳐주면된다.

위 vhost.conf 외에도

# vi /opt/docker/etc/nginx/vhost.common.d/10-php.conf

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME     $request_filename;
    fastcgi_read_timeout 600;

    try_files $uri =404;
}
location @extensionless-php {
      rewrite ^(.*)$ $1.php last;
}
# vi /opt/docker/etc/nginx/vhost.common.d/10-location-root.conf

location / {
    #try_files $uri $uri/ /index.php?$query_string;
    try_files $uri $uri.html $uri/ @extensionless-php;
    index index.html index.htm index.php;
}

여기저기 흩어져있어도 웬만한건 opt/docker/etc/nginx 안에 있으니 잘 찾아보면 원하는 설정대로 할 수 있다.

728x90
300x250