在 nginx 上部署 concrete5

在 nginx 上部署 concrete5

我有一个 concrete5 网站,可以在 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 文件,而不是通过具体的调度程序。

我完全迷失了。

提前谢谢你的帮助。

答案1

将配置更改为:

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;
    }
}

它之所以有效,是因为宿醉和关联他提供了。

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

答案2

看看下面的配置。它已用于 Debian 8、NGinx 和 PHP-FPM 7.1 我遇到的问题与仪表板 (ccm) 上的“访问被拒绝”以及几个不再工作的编辑块有关(开发是在 Apache 2.4 和 PHP 5.6 上使用 mod-apache 进行的)

重点是创建一个有效的“位置 /”try_files $uri $uri/ /index.php?q=$uri&$args;

server { listen 80; server_name www.example.com; root /var/www/example.com/www;

   index index.php index.html index.htm default.html default.htm;

    add_header Access-Control-Allow-Origin *;
    #add_header X-Frame-Options "ALLOWALL";

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

   location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
   }

    location / {
            # try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

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:/var/run/php/php7.1-fpm.sock;
}

}

相关内容