引言
这篇文章主要讲解安装完LNMP后对nginx和php的一些配置.
准配
开搞 = ̄ω ̄=
以下是以目录/var/share/blog
为例,目录自己随意选就行了,但是别太奇葩,在/var
,/usr
下选就行了.
1.为网站创建根目录
mkdir -p /usr/share/blog
2.下载typecho源码
cd /usr/local/src
yum install wget -y
wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz
tar -zxvf 1.1-17.10.30-release.tar.gz && mv bulid/* /usr/share/blog/
chown nginx:nginx -R /usr/share/blog/ #更改目录所有者
3.更改php-fpm
的用户
vim /etc/php-fpm.d/www.conf
#找到usr,group,并将其改为如下内容(与`nginx`的用户和组相同即可)
usr = nginx
group = nginx
#重启php
systemctl restart php-fpm
3.配置nginx
(80端口(http))
先查看nginx配置
vim /etc/nginx/nginx.conf
如果你的配置是如下形式:
http{
...
include /etc/nginx/conf.d/*.conf;
...
}
则在/etc/nginx/conf.d
目录下新建一个配置文件,
touch /etc/nginx/conf.d/blog.conf
并填上如下内容:
server {
listen 80 default_server;
#listen [::]:80 default_server;
server_name example.com; #修改为你的域名,无需加www
root /usr/share/blog; #你网站根目录
#rewrite ^(.*)$ https://$host$1 permanent; #http强制跳转htpps(选择开启)
add_header Strict-Transport-Security "max-age=31536000;includeSubDomains";
location / {
index index.html index.htm index.php;
#nginx重写规则,便于以后开启伪静态
#if (-f $request_filename/index.html){
# rewrite (.*) $1/index.html break;
#}
#if (-f $request_filename/index.php){
# rewrite (.*) $1/index.php;
#}
#if (!-e $request_filename){
# rewrite (.*) /index.php;
#}
}
#开启php支持
location ~ \.php$ {
root /usr/share/blog; #你网站根目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
如果过你的nginx.conf中已经含有了
server{
listen 80;
...
}
等内容,参照上面改一下就行了.
4.配置nginx
(443端口(https))
https的配置如下(阿里云,腾讯云适用):
server {
listen 443 ssl http2 default_server;
#listen [::]:443 ssl http2 default_server;
server_name example.com; #修改为你的域名,无需加www
root /usr/share/blog; #你网站根目录
ssl_certificate "/etc/nginx/cert/blog.pem"; #你的ssl证书所在位置
ssl_certificate_key "/etc/nginx/cert/blog.key"; #你的ssl密钥所在位置
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 60m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
index index.html index.htm index.php;
#nginx重写规则,便于以后开启伪静态
#if (-f $request_filename/index.html){
# rewrite (.*) $1/index.html break;
#}
#if (-f $request_filename/index.php){
# rewrite (.*) $1/index.php;
#}
#if (!-e $request_filename){
# rewrite (.*) /index.php;
#}
}
#开启php支持
location ~ \.php$ {
root /usr/share/blog; #你网站根目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
检查语法错误
nginx -t
重启nginx
systemctl restart nginx
在防火墙中方通80和443端口
systemctl restart firewalld
firewall-cmd --add-port=80/tcp --permanent --zone=public
firewall-cmd --add-port=443/tcp --permanent --zone=public
firewall-cmd --reload
现在去浏览器输入你的域名
http://example.com
这之间可能会报错,提示No input file specified
你只要找到php.ini
把cgi.fix_pathinfo = 0改为1就好了
find / -name php.in
如果出现如下内容则表示配置无误:
然后进入安装界面(如下图),数据库适配器
选择mysql
的,用这个教程获得数据库名和数据库账户来补全下面数据库的内容.
信息填写完后,typecho就会进行数据库配置,如果没有报错就代表安装成功了!O(∩_∩)O~~
本文由 giao创作, 采用 知识共享署名4.0 国际许可协议进行许可 本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名 原文地址:《安装完LNMP后对typecho的安装及配置》
最后一次更新于2018-12-21
0 条评论