【问题标题】:October CMS Install As A Subdirectory - /backend Not Found, Nginx Configuration Issue?十月 CMS 安装为子目录 - 找不到 /backend,Nginx 配置问题?
【发布时间】:2015-08-15 23:29:03
【问题描述】:

我有一个使用 laravel 4.2 的现有网站。我正在尝试在 /blog 子目录中安装 October CMS(仅用作博客和帮助部分),但 nginx 设置中的某些内容不正确。我执行了 10 月 CMS 安装向导,并且能够正确显示 /blog/index.php 页面。问题是当我尝试登录后端(/blog/backend)时,我得到一个 404 页面。以下是我为本网站的虚拟主机 nginx 配置:

server {
    listen 80;
    server_name my_site;
    root /home/vagrant/my_site/public;

    index index.html index.htm index.php;

    charset utf-8;

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

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

    access_log off;
    error_log  /var/log/nginx/my_site.app-error.log error;
    rewrite_log on;

    error_page 404 /index.php;

    sendfile off;

    # October CMS rewrites
    location blog {
        root /home/vagrant/my_site/public/blog;

        try_files $uri $uri/ /index.php$is_args$args;
    }

    rewrite ^/blog/themes/.*/(layouts|pages|partials)/.*.htm /blog/index.php break;
    rewrite ^/blog/bootstrap/.* /blog/index.php break;
    rewrite ^/blog/config/.* /blog/index.php break;
    rewrite ^/blog/vendor/.* /blog/index.php break;
    rewrite ^/blog/storage/cms/.* /blog/index.php break;
    rewrite ^/blog/storage/logs/.* /blog/index.php break;
    rewrite ^/blog/storage/framework/.* /blog/index.php break;
    rewrite ^/blog/storage/temp/protected/.* /blog/index.php break;
    rewrite ^/blog/storage/app/uploads/protected/.* /blog/index.php break;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300s;
        fastcgi_send_timeout 120;
        fastcgi_read_timeout 120;
    }

    location ~ /\.ht {
        deny all;
    }

}

如果我添加以下指令,我可以显示 /blog/backend 页面(尽管没有使用 css/js 设置样式):

rewrite ^/blog /blog/index.php break; 

请注意,使用上面的重写指令,/blog/index.php 页面的资产返回结果为 404,因此 /blog/index.php 页面也没有样式。但是,如果我删除上述指令,链接将再次起作用。

我是 nginx 新手并设置了 10 月 CMS,但无法弄清楚这一点。谢谢!

【问题讨论】:

    标签: nginx octobercms


    【解决方案1】:

    我不使用 October CMS,但查看您的配置,我认为不需要所有这些重写,您只需要正确设置 try_files 部分。

    看起来您还需要考虑您的根文件夹到底是什么。我在这里假设它是/home/vagrant/my_site/public/blog

    鉴于此,这应该适合您:

        Server {
    
        ....
    
        # Generally better to define root at server level
        root /home/vagrant/my_site/public/blog;
    
        location / {
            try_files $uri $uri/ /index.php;
        }
    
        # Use this instead if root folder is /home/vagrant/my_site/public
        #location /blog {
        #   try_files $uri $uri/ /blog/index.php;
        #}
    
    
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
            fastcgi_buffer_size 16k;
            fastcgi_buffers 4 16k;
            fastcgi_connect_timeout 300s;
            fastcgi_send_timeout 120;
            fastcgi_read_timeout 120;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    

    【讨论】:

    • 根文件夹是正确的,正如最初提到的 /home/vagrant/my_site/public 我正在尝试将十月 CMS 添加到现有的 laravel 应用程序中,其中十月 CMS 将只处理应用程序的博客和帮助部分。重写如 OctoberCMS 网站上的配置文档中所述:octobercms.com/docs/help/installation#nginx-configuration
    • 建议的配置似乎有点可疑,因为它没有关于 php 位置的任何内容,并且重写似乎只是将所有内容发送到 index.php,它通常复制 try_files 将执行的操作。不太确定写这篇文章的人是否真正了解 Nginx。试试我的建议配置看看。我发布了您拥有的任何根配置的选项。如果需要,您还可以添加重写。即使事实证明实际上不需要它们,它们也不会造成真正的伤害。
    • 好的 - 看起来你的 location blog { .... } 修复成功了(以及从 rewrite 指令中删除 /blog (那是我在那里工作的 nginx 无能。现在修复 - 谢谢!(只要他们允许我就会奖励赏金)。
    猜你喜欢
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多