我在 URL 重写方面遇到了一些问题。当我点击 Magento 后端的链接时,URL 完全乱了。
我们从这个链接开始:
http://icanttellmydomain.nl/index.php/paneel/dashboard/index/key/26f665360ac9f2e3e9b5c69b097fcb6b/
但我们被重定向到这里:
它不断重复“index.php”和 URL 的路径,循环直到给我 500 内部错误或“页面未正确重定向”。
我确信这与我的 vhost 配置有关。我尝试评论:
#Forward paths like /js/index.php/x.js to relevant handler
# location ~ .php/ {
# rewrite ^(.*.php)/ $1 last;
# }
但它没有起到作用。
我的虚拟主机:
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default_server ipv6only=on; ## listen for ipv6
listen 443 default ssl;
root /usr/share/nginx/www/xxxxxxxx/public/;
index index.html index.htm;
# Make site accessible from http://<serverip/domain>/
server_name xxx.xxx.xxx.xxx;
error_log /var/log/nginx/error.log; #warn; #op warn niveau word er logged
#access_log off; #Disabled voor I/O besparing
access_log /var/log/nginx/access.log;
location / {
index index.html index.php;
#autoindex on;
## If missing pass the URI to Magento's front handler
try_files $uri $uri/ @handler;
expires max; ##
}
## These locations need to be denied
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }
## Disable .htaccess and other hidden files
location /. {
access_log off;
log_not_found off;
return 404;
deny all;
}
## Magento uses a common front handler
location @handler {
rewrite / /index.php;
}
#Forward paths like /js/index.php/x.js to relevant handler
# location ~ .php/ {
# rewrite ^(.*.php)/ $1 last;
# }
##Rewrite for versioned CSS+JS via filemtime(file modification time)
location ~* ^.+\.(css|js)$ {
rewrite ^(.+)\.(\d+)\.(css|js)$ $1.$3 last;
expires 31536000s;
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "max-age=31536000, public";
}
## php-fpm parsing
location ~ \.php.*$ {
## Catch 404s that try_files miss
if (!-e $request_filename) { rewrite / /index.php last; }
## Disable cache for php files
expires off;
## php-fpm configuration
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
## Store code is located at Administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
## Tweak fastcgi buffers, just in case.
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
谢谢阅读!我对这些内容都很陌生,所以请在回复时考虑到这一点。
答案1
发布我的工作 nginx php 配置,在这里找到:http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/configuring_nginx_for_magento
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS on;
fastcgi_param HTTPS $https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE store_code; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
答案2
您的 location 块中的 try_files 指令可能有问题。@handler 块被视为 URI,每次页面重定向时都会附加到 URL 中。
您可以尝试将 try_files 指令更改为使用不同的 @ 块,例如 @missing,如果未找到请求的文件,它将返回 404 错误。这应该可以防止您遇到的循环重定向。
以下是如何修改位置块的示例:
location / {
index index.html index.php;
#autoindex on;
## If missing pass the URI to Magento's front handler
try_files $uri $uri/ @missing;
expires max; ##
}
## Magento uses a common front handler
location @missing {
return 404;
}
请记住,在进行任何更改之前备份您的配置文件,以防出现问题。您还可以尝试清除浏览器的缓存和 cookie,以确保更改生效。
答案3
我会这样做:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com; # Replace with your actual domain name
root /usr/share/nginx/www/xxxxxxxx/public/;
index index.html index.php;
error_log /var/log/nginx/error.log; # Specify the path to your error log
access_log /var/log/nginx/access.log;
location / {
try_files $uri $uri/ @handler;
expires max;
}
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock; # Adjust the PHP version and socket path as needed
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 300; # Increase the timeout if needed
}
location ~* \.(css|js)$ {
rewrite ^(.+)\.(\d+)\.(css|js)$ $1.$3 last;
expires 31536000s;
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "max-age=31536000, public";
}
location @handler {
rewrite / /index.php;
}
location /. {
access_log off;
log_not_found off;
return 404;
}
}
server {
listen 443 ssl;
server_name yourdomain.com www.yourdomain.com; # Replace with your actual domain name
ssl_certificate /etc/nginx/ssl/yourdomain.crt; # Specify your SSL certificate file path
ssl_certificate_key /etc/nginx/ssl/yourdomain.key; # Specify your SSL certificate key file path
root /usr/share/nginx/www/xxxxxxxx/public/;
index index.html index.php;
error_log /var/log/nginx/error.log; # Specify the path to your error log
access_log /var/log/nginx/access.log;
location / {
try_files $uri $uri/ @handler;
expires max;
}
# Other location blocks and PHP configuration (similar to the previous server block)
# Redirect HTTP requests to HTTPS
location / {
return 301 https://$host$request_uri;
}
}
答案4
请尝试这些解决方案
禁用
listen [::]:80 default_server ipv6only=on; ## 监听 ipv6
调整
索引 index.html index.htm; === 索引 index.php;
调整
位置 ~ .php.*$ { === 位置 ~ .php$ {
我不清楚那部分,所以请尝试禁用它
通过 filemtime(文件修改时间)位置 ~* ^.+.(css|js)$ 重写版本化的 CSS+JS { rewrite ^(.+).(\d+).(css|js)$ $1.$3 last; 过期 31536000 秒;access_log off; log_not_found off; add_header Pragma public; add_header Cache-Control "max-age=31536000, public"; }
刷新缓存并禁用缓存,使用私人浏览器进行测试