07/01/2015
WordPress Permalinks on LEMP
最近一个工程项目涉及到网站搬迁,从虚拟主机搬到VPS上,当然使用的是我最喜爱的LEMP精简方案(LAMP太吃内存,多占的内存都可以够我装一个主机控制面板了),虽然LEMP功能实用稳定,美中不足便是设置极为繁琐(想完美不容易)。
这不,主机假设轻车熟路,解决了一系列的小问题,网站上线之后发现伪静态协议失效,只有主页能够显示。
首先,想到了可以更新网站静态链接格式(变成类似本网站的?p=xxx的格式),但这属于避开问题,而且会影响收录,所以放弃。
之后就开始想办法手动解决伪静态的问题,终于在一个网站找到一篇非常详细的设置文章,经过实际测试成功!
下面只粘贴认为最核心的代码,phpmyadmin之类的设置可以参考以前的文章。
server {
listen 80;
server_name www.bjdch.org bjdch.org;
access_log /srv/www/bjdch.org/logs/access.log;
error_log /srv/www/bjdch.org/logs/error.log;
root /srv/www/bjdch.org/public_html;
index index.html index.htm index.php;#PHP Settings
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
if ($uri !~ “^/uploads/”) {
fastcgi_pass 127.0.0.1:9000;
}
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/bjdch.org/public_html$fastcgi_script_name;
}location / {
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}# Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_
{
return 444;
}
#nocgi
location ~* \.(pl|cgi|py|sh|lua)\$ {
return 444;
}
#disallow
location ~* (roundcube|webdav|smtp|http\:|soap|w00tw00t) {
return 444;
}location ~ /(\.|wp-config.php|readme.html|license.txt) { deny all; }
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;try_files $uri $uri/ /index.php?q=$request_uri;
}#Error outputs:
error_page 400 /400.shtml;
error_page 401 /401.shtml;
error_page 403 /403.shtml;
error_page 404 /404.shtml;
error_page 500 502 503 504 /500.shtml;}
Thanks: http://centminmod.com/nginx_configure_wordpress.html
16/04/2024
NGINX config with WordPress and Moodle
By dch1 in Just Notes No Comments Tags: Moodle, Nginx, VPS
Working config for Moodle config:
nginx.conf file:
sites.conf file:
Working config for WordPress: