Nginx PHP文件明文呈现

Nginx PHP文件明文呈现,nginx,php,Nginx,Php,我有一个主域example.com和一个example.com/admin/。此管理域具有不同的文档根,将呈现管理界面。目前的问题是,该文件是nginx提供的服务器纯文本文件。所以我基本上可以看到index.php文件。我正在努力想办法,但还没有成功 这是我的nginx配置: server { listen 127.0.0.1:8080; server_name www.example.me; rewrite ^(.*) http://example.me$1 perma

我有一个主域example.com和一个example.com/admin/。此管理域具有不同的文档根,将呈现管理界面。目前的问题是,该文件是nginx提供的服务器纯文本文件。所以我基本上可以看到index.php文件。我正在努力想办法,但还没有成功

这是我的nginx配置:

server {
    listen 127.0.0.1:8080;
    server_name www.example.me;
    rewrite ^(.*) http://example.me$1 permanent;
}

server {
    listen 127.0.0.1:8080;
    server_name example.me;
    root /var/www/example.me/laravel/example/public/;
    index  index.html index.htm index.php;

    error_log /var/log/nginx/example.me.error.log error;
        access_log /var/log/nginx/example.me.access.log;

    port_in_redirect off;

    merge_slashes on;
    client_max_body_size 20M;

    error_page 404 =301 http://example.me;

    location / {
        #Don't use slash at end
        rewrite ^/(.*)/$ /$1 permanent;

        # add rewrite rule here:
        # block access to /index.(php|htm|html)
        if ($request_uri ~ "/index.(php|html?)") {
            rewrite ^ /$1 permanent;
        }


        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
        }


    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

    }

    location ^~ /admin {
        root /var/www/example.me/zend/public/;
        index index.php;
        try_files /index.php$is_args$args $uri;

        auth_basic            "example Admin";
                auth_basic_user_file  /var/www/example.me/zend/public/.htpasswd;

        rewrite_log on;

        access_log /var/log/nginx/adminexample.access.log;
                error_log /var/log/nginx/adminexample.error.log notice;

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            #fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            #fastcgi_param SCRIPT_FILENAME /var/www/example.me/zend/public$fastcgi_script_name;
        }
    }
}

nginx不能同时选择两个位置。因此,如果它在
location^~/admin
中使用
location~\.php$
,则第二个选项不会被继承。