0

这是我的Nginx的配置

server {
    listen       80;
    server_name  localhost;

    charset utf-8;
    root /opt/build;
    index index.html index.htm index.php;

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

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

    location ~ .*\.php(\/.*)*$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

http://server_name/index.php/*这种格式的路由都能正常访问,但是点击登录http://server_name/admin/login.php就是把login.php页面下载下来。原因应该是php-fpm没有执行这个脚本。可能Nginx配置的路由有问题,我的配置是按照官方文档配的,请问如何解决呢?谢谢。

Nginx: 1.10.3
PHP: 7.1.3

查看全部 2 个回答

0

这是我所使用的配置,请试用一下?

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

location ~ .+\.php(/.*)?$ {
    fastcgi_split_path_info ^(.+\.php)(/.*)?$;
    # save $fastcgi because try_files will reset it
    set $path_info $fastcgi_path_info;
    # Check that the PHP script exists before passing it
    try_files $fastcgi_script_name =404;
    # Bypass the fact that try_files resets $fastcgi_path_info
    # see: http://trac.nginx.org/nginx/ticket/321
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_pass unix:/usr/local/var/run/php-fpm.sock;
}