如果你使用joomla, 使用的是nginx作为web 服务的话, 你可能会面临和我们一样的问题,只能访问首页,访问其他页面出现404错误,而且, 在URL连接里会出现index.php。 如果之前我们用apache的时候, 只要开启mod_rewrite, 然后把htaccess.txt 改成.htaccess就能正常使用了, 但是在nginx下, 该怎么配置尼?
我google了很多,看了官网上的说明和帮助,都没有效, 最终发现一个有效的方法。 请按照下面一样设置站点的配置文件:
server {
listen 80;
server_name example.com;
root /var/www/example/public_html;
index index.php index.html index.htm default.html default.htm;
access_log /var/log/nginx/accn_access.log;
error_log /var/log/nginx/accn_error.log;
##
# JOOMLA SEF
##
location / {
try_files $uri $uri/ /index.php?q=$request_uri&$args;
}
##
# PHP scripts to FastCGI
##
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
这个有效的重点在于, 这一行:
try_files $uri $uri/ /index.php?q=$request_uri;
意思把URI当做一个参数q传给了index.php, 这个joomla的入口文件,然后估计joomla内部有机制实现转换。
如果有joomla的商业合作,请联系我i#mengxi.me