总结
WordPress 的安装其实也没什么可说的。如果是做独立站的话,无技术能力的,直接选择siteground或者其他三方托管服务即可。本文只记录一下个人在搭建wordpress过程中的服务器简单优化,后期遇到的其他问题,会再更新
前提
LNMP 的环境已搭建完成
下载wordpress
中文版:https://cn.wordpress.org/latest-zh_CN.tar.gz
原版:https://wordpress.org/latest.zip
想最新的就原版吧,安装过程都一样的,解压即可
提示 wp-config.php 无法写入的问题
一般来说就是目前权限的问题, 注意nginx 和 php 需要在同一个用户组下启动,修改wordpress的目录权限
chown -R [用户组].[用户组] wordpress
此处把wordpress的目录全部允许可写入了,自主学习使用没有问题,如果用于生产环境,建议安装后,重新分配一下权限
上传文件大小的限制
默认我记得是2M的限制,但是一些插件包很快就超过此大小
修改 php.ini upload_max_size 的大小
多站点配置
在wp-config.php中加入
/* Add any custom values between this line and the "stop editing" line. */
define('WP_ALLOW_MULTISITE', true);
/* That's all, stop editing! Happy publishing. */
之后在 工具-网络配置中就可以看到多站点的配置提示,选择子域名 和 子目录形式会有不同的配置说明
下面附可用的多目录nginx
更多配置说明
map $uri $blogname{
~^(?P<blogpath>/[^/]+/)files/(.*) $blogpath;
}
map $blogname $blogid{
default -999;
#Ref: https://wordpress.org/extend/plugins/nginx-helper/
#include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ;
}
server {
listen 80;
server_name 自己的域名;
root /home/www/wordpress;
index index.php index.html index.htm;
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
location ~ ^(/[^/]+/)?files/(.+) {
try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ;
access_log off;
log_not_found off; expires max;
}
#avoid php readfile()
location ^~ /blogs.dir {
internal;
alias /home/www/wordpress/wp-content/blogs.dir ;
access_log off;
log_not_found off;
expires max;
}
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$request_uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
网友评论