介绍一下Question2Answer在Nginx中的全部正确配置,网上找来的太杂!基于Q2A 1.7.x版
找到自己服务器的nginx配置文件,例如 /etc/nginx/conf.d/https123.conf,加入以下配置文件,并重启nginx服务:
结束的时候,一定要勾选General - URL structure: - /123/why-do-birds-sing (requires htaccess file)
server {
listen 80;
server_name www.sslzoo.com sslzoo.com;
# 配置网站根目录
root /home/test/https123;
index index.php index.html index.htm;
# 配置顶级域名到 www 的跳转,根据你的服务器实际情况看是否需要,无需则删
if ($host = 'sslzoo.com' ) {
rewrite ^/(.*)$ http://www.sslzoo.com/$1 permanent;
}
# 防止tpl inc cfg文件被下载,假如你可能不想让less,scss或者inc文件不被下载。
location ~* \.(tpl|inc|cfg|ico|less|scss)$ {
deny all;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# 重写规则,这样写才会防止 sslzoo.com/qa-theme/ 被访问
location / {
try_files $uri $uri/ /index.php?qa-rewrite=$uri&$args;
}
# 标准的php配置
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock; # use this if PHP-FPM is running on Unix socket /var/run/php5-fpm.sock (Ubuntu 12.10 default)
#fastcgi_pass 127.0.0.1:9000; # use this if PHP-FPM is running on TCP port 9000 (Debian Squeeze default)
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
}
}
这样既保证了重要文件的安全,又能做到完美SEO