最近在折腾一个magento项目,使用了宝塔,感觉挺方便。项目之前使用的apache作为http服务器,运行确实有点慢,手贱换成了Ngix,然而问题就出现了。网站index可以打开,但是二级页面却全部404了,分析原因主要是因为网站开启了伪静态。贴出Ngix配置代码,有同等病症的童鞋自取:
#START-SITE
server {
listen 80;
server_name www.prasadini.com;
access_log logs/www.prasadini.com.access.log;
root D:/wwwroot/Magento-EE-Advanced;
index index.php default.php index.html index.htm default.html default.htm;
include rewrite/www.prasadini.com.conf;
#START-ERROR-PAGE
error_page 403 /403.html;
## error_page 404 /404.html;
error_page 502 /502.html;
#END-ERROR-PAGE
#301-START
#301-END
#REFERER-START
#REFERER-END
#PROXY-START
#PROXY-END
#START-SSL
#END-SSL
## SSL CONFIGURATION
#ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location = /js/index.php/x.js {
rewrite ^(.*\.php)/ $1 last;
}
## Main Magento @location
location / {
try_files $uri $uri/ @rewrite;
}
location /. {
return 404;
}
## These locations are protected
location ~ /(app|var|downloader|includes|pkginfo)/ {
deny all;
}
## Images
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
access_log off;
add_header ETag "";
}
## Fonts
location ~* \.(swf|eot|ttf|otf|woff|woff2)$ {
expires max;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin "example.com, cdn.example.com";
add_header Cache-Control "public";
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
#START-PHP
location @rewrite {
rewrite / /index.php;
}
location ~ \.php$ {
root D:/wwwroot/Magento-EE-Advanced;
fastcgi_pass 127.0.0.1:4556;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
try_files $uri =404;
#fastcgi_param MAGE_RUN_CODE $mage_code;
#fastcgi_param MAGE_RUN_TYPE $mage_type;
fastcgi_keep_conn on;
}
#END-PHP
}
#END-SITE
修改完成后重启Ngix,刷新,一切正常,运行如飞。