Joomla URL重写在Nginx中自动运行

这是驱使我坚果,我不明白这是如何工作自动。 我有nginx作为我的networking服务器,我已经安装了URL重写的Joomla从URL删除index.php 。 之前,当我使用Apache时,必须使用RewriteEngine On启用.htaccess才能使其工作。 但对于Nginx,当启用“使用URL重写”时,它会自动运行。 我只使用将php文件传递给php-fpm的Nginx。 就这样。 我没有添加任何特殊的重写规则,而不是Joomla文档中给出的。 我不明白“启用URL重写”是如何自动启用的,因为Nginx没有.htaccess。

关于这个主题的Joomla文档没有帮助。 它在第二步说

启用使用Apache mod_rewrite / URL重写选项并保存:此选项使用Apache mod_rewrite函数来消除URL的“index.php”部分。

…..

如果此选项导致错误,请参阅如何检查您的服务器上是否启用了mod重写。 如果未启用,并且您有权访问文件apache / conf / httpd.conf,请打开该文件并检查LoadModule行rewrite_module modules / mod_rewrite.so是否未注释。 如有必要,取消注释该行并重新启动Apache Web服务器。

不知道为什么这是在Nginxconfiguration中添加的,因为在Nginx中没有mod_rewrite。 Joomla后端的URL重写如下:

使用URL重写select使用服务器的重写引擎来捕获满足特定条件的URL,并按照指示重写它们。 适用于IIS 7和Apache。 仅限Apache用户! 激活之前,将htaccess.txt重命名为.htaccess。 将web.config.txt重命名为web.config,然后在激活之前安装IIS URL重写模块。

它没有提到Nginx,但仍然有效。 我在这里挠着脑袋。 有人能告诉我Joomla的index.php如何轻松地在Nginx中删除? 这是我的Nginx Vhostconfiguration:

 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; } ## # 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; } } 

看到..它是一个非常简单的configuration。 魔术在哪里发生?

魔术发生在这里:

 try_files $uri $uri/ /index.php?q=$request_uri; 

这意味着如果文件系统上存在请求的文件或目录,nginx会先检查。 如果文件不存在,它将请求传递给Joomla,并将原始URI传递给q参数。