十月 CMS 安装为子目录 - /backend 未找到,Nginx 配置问题?
October CMS Install As A Subdirectory - /backend Not Found, Nginx Configuration Issue?
我有一个使用 laravel 4.2 的现有网站。我试图在 /blog 子目录中安装 October CMS(仅用作博客和帮助部分),但 nginx 中的某些设置不正确。我执行了 October 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 和设置 October CMS,无法解决这个问题。谢谢!
我不使用 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;
}
}
我有一个使用 laravel 4.2 的现有网站。我试图在 /blog 子目录中安装 October CMS(仅用作博客和帮助部分),但 nginx 中的某些设置不正确。我执行了 October 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 和设置 October CMS,无法解决这个问题。谢谢!
我不使用 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;
}
}