1

我有一个可在 apache 服务器中“开箱即用”的具体站点。但是我在 nginx 中运行它时遇到了很多麻烦。

以下是我正在使用的 nginx 配置:

server {
    root /home/test/public;
    index index.php;

    access_log /home/test/logs/access.log;
    error_log /home/test/logs/error.log;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ index.php;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }
    # pass the PHP scripts to FastCGI server listening on unix socket
    #
    location ~ \.php($|/) {
            fastcgi_pass unix:/tmp/phpfpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            include fastcgi_params;
    }
    location ~ /\.ht {
            deny  all;
    }
}

我能够获得主页,但内页有问题。内页显示“拒绝访问”。可能重写不起作用,实际上我认为它查询并尝试直接执行 php 文件,而不是通过具体的调度程序。

我完全迷失在这里。

提前谢谢你的帮助。

4

1 回答 1

3

将配置更改为:

server {
    root /home/test/public;
    index index.php;

    access_log /home/test/logs/access.log;
    error_log /home/test/logs/error.log;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ /index.php/$request_uri;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

    # pass the PHP scripts to FastCGI server listening on unix socket
    #
    location ~ \.php($|/) {
            set $script $uri;
            if ($uri ~ "^(.+\.php)(/.+)") {
                    set $script $1;
            }
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$script;
            fastcgi_intercept_errors on;
            fastcgi_pass unix:/tmp/phpfpm.sock;
    }

    location ~ /\.ht {
            deny  all;
    }
}

多亏了 hangover 和他在 serverfault 中提供的链接,它才有效。

我仍然不清楚我做错了什么,也许 nginx 专家可以帮助我理解。

于 2012-06-27T16:39:39.697 回答