首先说一下,我不懂web开发,全靠google出来的。
服务器安装v2后,已经配置了NGINX,想着折腾一个博客,然后就想起了之前安装过的Typecho博客程序,然后就开始坑程了。
打开Typecho官网,找到下载链接,wget到服务器后,tar -vxf 解压,得到build文件夹,可以改名Typecho,按照知乎专栏:Centos7下配置PHP + MySQL + Nginx开发环境的方法安装了PHP和配置了MySQL,重新设置了密码和端口。PHP,MySQL的安装及添加配置到nginx配置文件,遇到的难题,下面那句配置(作者写的时候没有空格),nginx一直提示出错,后面搜其他网页才知道是有空格的:
fastcgi_param SCRIPT_FILENAME 空格 $document_root$fastcgi_script_name;
我的配置是:
server {
listen 80;
server_name xxx.xxxx.com; # 你的域名
root /home/wwwroot/Typecho;
index index.php; #能访问php文件,不能访问目录的关键
}
location ~ ^(.+\.php)(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
if (!-e $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
设置好以后,重启nginx,访问xxx.com/install.php,发现是下载文件,没法安装,然后就按照Nginx+PHP-fpm网站目录权限问题的方法,主要操作如下如下:
# cd /home/wwwroot/Typecho
# find -type d -exec chmod 755 {} \;
# find -type f -exec chmod 644 {} \;
默认Typecho解压出来的拥有者不是root,需要改一下
# chown -R root:root /home/wwwroot/Typecho
我还改了一下nginx.conf 的第一行:
user root;#(默认是nginx)
安装好了后,发现目录不能用,只能访问文件,折腾了一下午最后看到在Nginx服务器上安装配置博客程序Typecho的教程
上location 外面还要添加下面这句话:
index index.php;
然后就正常了(泪奔。。。)
通过Typecho全站启用HTTPS教程,需要申请网站证书,我已提前申请Let's Encrypt证书,网站也提供申请教程的连接CentOS申请Let’s Encrypt免费SSL证书,请自行申请,部署证书后,按照教程在config.inc.php 添加如下代码
/** 开启HTTPS */
define('__TYPECHO_SECURE__',true);
对于chrome浏览器的支持,按照网站原话:
即:
$this->commentUrl() 替换为 echo str_replace("http","https",$this->commentUrl());
最后按照Nginx强制https,HTTP 301重定向到HTTPS教程,添加server 443和server 80虚拟机代码,并把http/80重定向到https/443,请参考如下代码:
server {
listen 443 ssl http2;
ssl on;
ssl_certificate /etc/v2ray/blog.crt; #证书我用的是Let's Encrypt
ssl_certificate_key /etc/v2ray/blog.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
server_name xxxx.com;
root /home/wwwroot/Typecho;
index index.php;
location ~ ^(.+\.php)(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
if (!-e $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name blog.xxx.com;
rewrite ^(.*) https://blog.xxx.com$1 permanent;#修改内容,重定向http:80到https:443
}
Have fun...