0

我有一个使用 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; 

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

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

4

1 回答 1

2

我不使用十月 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;
    }
}
于 2015-08-18T00:40:59.500 回答