使用 nginx 的 magento 中某些内部子商店页面出现 404 错误
404 error for some internal sub-store pages in magento with nginx
我无法访问我商店的某些内部页面,但是禁用 web/seo/use_rewrites 它可以正常工作。
我认为是某些nginx配置不对,我尝试创建一个rewriter,但是有很多地方。
- 工作:https://127.0.0.1/
- 工作:https://127.0.0.1/rj/
- 工作:https://127.0.0.1/sp/
- 不要工作:https://127.0.0.1/rj/customer/account/forgotpassword/
- 不要工作:https://127.0.0.1/sp/sociallogin/social/login/type/facebook/
这是我的配置文件:
upstream fastcgi_backend {
server unix:/run/php-fpm/www.sock;
}
server {
listen 80 reuseport default_server;
server_name _;
root /var/www;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .php/ {
rewrite ^(.*.php)/ last;
}
location ~ (index|get|static|errors/report|errors/404|errors/503|health_check)\.php {
fastcgi_pass fastcgi_backend;
fastcgi_index index.php;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_log /var/log/nginx/debug.log debug;
access_log /var/log/nginx/debug.log;
}
如果我设法让一个重写器在每个文件夹子存储之后添加一个 index.php,我想问题就解决了。
我试图创建一个规则来始终添加 index.php,但是它下载而不是被执行。
location / {
try_files $uri $uri/ /index.php$is_args$args @fallback;
}
location @fallback {
rewrite ^/(\w*)/(.*)$ //index.php/ last;
}
好的,nginx 会按照写入的顺序读取位置,所以我需要为子商店创建一个规则,我不得不重新排序,这样就不会有规则的无限循环。
这是我所做的:
location ~ (index|get|static|errors/report|errors/404|errors/503|health_check)\.php {
fastcgi_pass fastcgi_backend;
fastcgi_index index.php;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/([a-z]+)/(.*)$ {
try_files $uri $uri/ //index.php/?$query_string;
}
location ~ .php/ {
rewrite ^(.*.php)/ last;
}
我无法访问我商店的某些内部页面,但是禁用 web/seo/use_rewrites 它可以正常工作。
我认为是某些nginx配置不对,我尝试创建一个rewriter,但是有很多地方。
- 工作:https://127.0.0.1/
- 工作:https://127.0.0.1/rj/
- 工作:https://127.0.0.1/sp/
- 不要工作:https://127.0.0.1/rj/customer/account/forgotpassword/
- 不要工作:https://127.0.0.1/sp/sociallogin/social/login/type/facebook/
这是我的配置文件:
upstream fastcgi_backend {
server unix:/run/php-fpm/www.sock;
}
server {
listen 80 reuseport default_server;
server_name _;
root /var/www;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .php/ {
rewrite ^(.*.php)/ last;
}
location ~ (index|get|static|errors/report|errors/404|errors/503|health_check)\.php {
fastcgi_pass fastcgi_backend;
fastcgi_index index.php;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_log /var/log/nginx/debug.log debug;
access_log /var/log/nginx/debug.log;
}
如果我设法让一个重写器在每个文件夹子存储之后添加一个 index.php,我想问题就解决了。
我试图创建一个规则来始终添加 index.php,但是它下载而不是被执行。
location / {
try_files $uri $uri/ /index.php$is_args$args @fallback;
}
location @fallback {
rewrite ^/(\w*)/(.*)$ //index.php/ last;
}
好的,nginx 会按照写入的顺序读取位置,所以我需要为子商店创建一个规则,我不得不重新排序,这样就不会有规则的无限循环。
这是我所做的:
location ~ (index|get|static|errors/report|errors/404|errors/503|health_check)\.php {
fastcgi_pass fastcgi_backend;
fastcgi_index index.php;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/([a-z]+)/(.*)$ {
try_files $uri $uri/ //index.php/?$query_string;
}
location ~ .php/ {
rewrite ^(.*.php)/ last;
}