http://xenforo.com/help/friendly-urls/ PHP: #Nginx#To enable friendly URLs in Nginx, you must put the following in your server configuration:location /xf/ { try_files $uri $uri/ /xf/index.php?$uri&$args; index index.php index.html;}location /xf/internal_data/ { internal;}location /xf/library/ { internal;}location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}The /xf/ paths must be changed to match your XenForo installation path. 以上是官网的rewrite,以上只适合自己编译的LNMP环境,而且没有使用VHOST虚拟主机的情况下。上面除了/xf/需要修改成为你自己的web路径外,还需要修改“fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;”成你自己安装的路径。 对于上述,我个人比较嫌麻烦,我使用的是lnmp一键安装包,所以2楼是我使用虚拟主机环境,使用rewrite。
PHP: #example.com 不是我的域名,只是个例子。#这是我创建的虚拟主机的默认配置,一般配置文件会在/usr/local/nginx/conf/vhost/www.example.com.conf#./vhost 的过程中会提示是否使用rewrite,选择使用,后面会出现比较常用的网站程序的rewrite 规则,默认是other,选择这个。server {listen 80;server_name www.example.com example.com;access_log off;index index.html index.htm index.jsp index.php;include other.conf;root /home/wwwroot/xf;#error_page 404 /404.html;if ( $query_string ~* ".*[\;'\<\>].*" ){ return 404; }location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv)$ { valid_referers none blocked *.example.com www.example.com example.com; if ($invalid_referer) { return 403; } }location ~ .*\.(php|php5)?$ { #fastcgi_pass remote_php_ip:9000; fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; }location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; }location ~ .*\.(js|css)?$ { expires 7d; }} 创建好虚拟主机后,你可以使用vi 命令打开你自己对应路径的配置文件。我个人喜欢SFTP,因为SSH卡的时候,vi 很累。 vi /usr/local/nginx/conf/vhost/www.example.com.conf #加入下面的配置 PHP: location / { try_files $uri $uri/ /index.php?$uri&$args; }location ~ /(internal_data|library) { internal; } #结果就是下面的完整配置 PHP: server {listen 80;server_name www.example.com example.com;access_log off;index index.html index.htm index.jsp index.php;include other.conf;root /home/wwwroot/xf;#error_page 404 /404.html;if ( $query_string ~* ".*[\;'\<\>].*" ){ return 404; }location / { try_files $uri $uri/ /index.php?$uri&$args; }location ~ /(internal_data|library) { internal; }location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv)$ { valid_referers none blocked *.example.com www.example.com example.com; if ($invalid_referer) { return 403; } }location ~ .*\.(php|php5)?$ { #fastcgi_pass remote_php_ip:9000; fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; }location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; }location ~ .*\.(js|css)?$ { expires 7d; }} 使用下面的命令重启,让nginx重新加载配置文件。xenforo 后台设置friendly url 不用我说了吧。 service nginx restart