简体   繁体   English

未找到Magento内部页面404,但使用Nginx服务器获取主页

[英]Magento inner pages 404 Not Found but homepage getting with nginx server

This is my host file: 这是我的主机文件:

server {
  root     /path/to/root/domain/html;
  index    index.php;
  server_name servername.de;
  location / {
    index index.html index.php;
    try_files $uri $uri/ @handler;
    expires 30d;
  }
  location ^~ /(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
  location /var/export/ { internal; }
  location /. { return 404; }
  location @handler { rewrite / /index.php; }
  location ~* .php/ { rewrite ^(.*.php)/ $1 last; }
  location ~* .php$ {
    if (!-e $request_filename) { rewrite / /index.php last; }
    expires off;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param MAGE_RUN_TYPE store;
    include fastcgi_params;
 }
}

I have changed "Use Web Server Rewrites" to "Yes" from Magento Admin panel to make the Urls SEO friendly(without index.php). 我已经从Magento的“管理”面板中将“使用Web服务器重写”更改为“是”,以使Urls SEO友好(没有index.php)。 And i have cleared the magento cache from admin panel after restarting the nginx. 重新启动nginx之后,我已经从管理面板中清除了magento缓存。 Can anyone help me to find out that the nginx configured correctly or why am getting this error. 谁能帮助我找出正确配置的nginx或为什么会出现此错误。

You may try this configuration: 您可以尝试以下配置:

server {
    root     /path/to/root/domain/html;
    index    index.php;
    server_name servername.de;

    location / {
        index index.html index.php;
        try_files $uri $uri/ @handler;
        expires 30d;
    }
    location @handler { rewrite / /index.php; }
    location ~* .php/ { rewrite ^(.*.php)/ $1 last; }
    location ~* .php$ {
        if (!-e $request_filename) { rewrite / /index.php last; } 

        expires off;

        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        fastcgi_param  MAGE_RUN_CODE default; 
        fastcgi_param  MAGE_RUN_TYPE store;
    }

    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 @handler {
        rewrite / /index.php;
    }

    location ~ /\. {
       deny all;
       access_log off;
       log_not_found off;
    }
    location = /favicon.ico {
       log_not_found off;
       access_log off;
    }
    location = /robots.txt {
       allow all;
       log_not_found off;
       access_log off;
    }
}

Also, for this and related issues, you may check the official Magento guides: https://www.magentocommerce.com/wiki/1_-_installation_and_configuration/configuring_nginx_for_magento 另外,对于此问题和相关问题,您可以查看Magento官方指南: https : //www.magentocommerce.com/wiki/1_-_installation_and_configuration/configuring_nginx_for_magento

这句话对我来说很重要。

location ~* .php/ { rewrite ^(.*.php)/ $1 last; }

Myself fixed the issue. 我自己解决了这个问题。 I was using Plesk and there was an option to add Additional nginx directives. 我正在使用Plesk,并且可以选择添加其他nginx指令。 I removed the host file “/etc/nginx/conf.d/DOMAIN.conf”(Individual sites section in https://www.magentocommerce.com/wiki/1_-_installation_and_configuration/configuring_nginx_for_magento . Remember to configure “/etc/nginx/nginx.conf” properly.) and added the below code in my "Additional nginx directives" admin area in Plesk. 我删除了主机文件“/etc/nginx/conf.d/DOMAIN.conf"(Individual网站部分https://www.magentocommerce.com/wiki/1_-_installation_and_configuration/configuring_nginx_for_magento 。请记住配置“的/ etc / nginx的/nginx.conf”),并在我的Plesk的“其他nginx指令”管理区域中添加了以下代码。

location / {
    index index.html index.php;
    try_files $uri $uri/ @handler;
    expires 30d;
}

location /. {
    return 404;
}

location @handler {
    rewrite / /index.php;
}

location ~ .php/ {
    rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ {
    if (!-e $request_filename) {
    rewrite / /index.php last;
    }
    fastcgi_pass fastcgi_backend;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi.conf;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM