nginx server configuration returns php code

前端 未结 1 1648
庸人自扰
庸人自扰 2021-01-15 08:09

I have a nginx server and all seems to work finde but when I add a auth for a directory the server returns the php code as download.

server {
listen 80 defau         


        
相关标签:
1条回答
  • 2021-01-15 08:22

    nginx processes a request by choosing a location. The new location does not contain the necessary code to execute PHP. You should add a nested location block to process PHP within the /auth/ directory.

    location ^~ /auth/ {
        try_files $uri $uri/ =404;
        auth_basic "Auth";
        auth_basic_user_file /etc/nginx/.htpasswd;
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
    }
    ...
    location ~ \.php$ { ... }
    
    0 讨论(0)
提交回复
热议问题