지식공유
DXCMS

CMS 설치시 NGINX 환결설정 문제 발생시 참조

- 2026. 09. 30 11:34 23
기존 nginx.conf.example 파일에서 참조해서 수정하였으나 이상하게 홈페이지 접속시 다운로드 받으라고 나오고.....
관리자모드 접속시 접속 에러 영어로 뭐라뭐라~~ 나오던데.....
아래와 같이 수정하여 해결하였습니다
fastcgi_pass unix:/tmp/php-cgi-83.sock; 부분은 본인에게 맞는 php 버전으로 변경하셔야 합니다


    # data/ 폴더 직접 접근 차단 (업로드·설정·세션 보호)
    location ^~ /data/ {
        deny all;
        return 403;
    }

    # assets/ 정적 파일 직접 서빙
    location ^~ /assets/ {
        expires 30d;
        access_log off;
    }

    # install/ 설치 마법사 — PHP 실행 허용
    location ^~ /install/ {
        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/php-cgi-83.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PHP_VALUE "display_errors=1";
        }
    }

    # 모든 요청 → 루트 index.php 로 라우팅
    # admin/, boards/ 등 실제 디렉토리가 있어도 무시하고 index.php로 보냅니다.
    location / {
        try_files $uri /index.php?$query_string;
    }

    # PHP FastCGI (루트 index.php 및 라우팅된 요청 실행)
    # try_files 내부 리다이렉트를 확실하게 잡아채도록 위치 지정(named location) 구조를 결합한 안전한 방식입니다.
    location ~ ^/index\.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/php-cgi-83.sock;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        fastcgi_param PHP_VALUE "display_errors=0 \n log_errors=1";
        fastcgi_intercept_errors on;
        fastcgi_read_timeout 60;
    }

    # 그 외 하위 .php 파일 직접 실행 차단 (보안 강화)
    # install/ 및 루트 index.php를 제외한 모든 직접적인 .php 호출을 막습니다.
    location ~ \.php$ {
        deny all;
        return 403;
    }

    # 숨김 파일 차단
    location ~ /\. {
        deny all;
        return 404;
    }

    # 에러 페이지
    error_page 403 404 /index.php;
댓글 4

댓글을 작성하려면 로그인이 필요합니다.

목록 로그인