nginx, PHP 파일 제공

nginx, PHP 파일 제공

내 nginx 가상 호스트가 PHP 파일을 제공하지 못합니다. 대신 index.php브라우저에서 실행될 때 파일을 다운로드합니다. 내 구성은 다음과 같습니다.

/etc/nginx/sites-available/laravel.local

server {
    listen 80;
    server_name laravel.local www.laravel.local;
    root /var/www/laravel.local/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

/etc/nginx/sites-사용 가능/기본

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

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
           fastcgi_pass unix:/run/php/php8.1-fpm.sock;
           include snippets/fastcgi-php.conf;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

정적 파일을 제공할 때 다른 가상 호스트가 작동 중입니다 .html. PHP 서비스를 제공하려고 하면 문제가 시작됩니다.

여기에 이미지 설명을 입력하세요

답변1

특히 Chrome의 브라우저 문제인 것 같습니다. Chrome은 HTTP를 통해 문서를 제공하는 것을 좋아하지 않으며 문서를 제공하는 대신 HTTPS만 사용하고 다운로드합니다. 브라우저 캐시 새로 고침 후에도 마찬가지입니다. 증거는 예를 들어 Firefox에서 작동합니다.

여기에 이미지 설명을 입력하세요

관련 정보