如何制作服务器块配置文件以在NGINX服务器上运行CakePHP应用程序



由于我是Digitalocean的新手和Nginx服务器,所以我不知道我在做什么

说这是我遇到的问题

我已经将CakeApp文件夹放入/var/www/html文件夹中,还将info.php页面添加到我的cakeapp的Webroot文件夹中,以检查我是否可以访问

当我转到http://my_ip/CakeApp时,它将其重定向到http://my_ip/CakeApp/login页面并给出404,但是当我通过转到http://my_ip/CakeApp/info.php访问info.php文件时,它可以正常工作并返回PHP信息页

这是Sever Block文件

server {
    listen   80;
    listen   [::]:80;
    server_name app.cake.com;
    return 301 http://app.cake.com$request_uri;
    root   /var/www/html/CakeApp/public/webroot;
    index  index.php;
    location /CakeApp/webroot {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ .php$ {
        try_files $uri =404;
        include 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;
}

所以当我进入http://my_ip/CakeApp

时,我想获取登录页面

找到了一个修复。

server {
        listen 80;
        root /var/www/html/CakeApp/webroot;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name example.com;
        location / {
                rewrite ^(.+)$ $1 break;
                try_files $uri $uri/ /index.php$is_args$args;
        }
        location ~ .php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
        location ~ /.ht {
                deny all;
        }
}

最新更新