1.安装nginx
1.命令
apt-get install nginx
2.nginx
#启动服务
sudo systemctl start nginx
#停止服务
sudo systemctl stop nginx
#重启
sudo systemctl restart nginx
#设置开机启动
sudo systemctl enable nginx
#重新载入配置文件
nginx -s reload
3.配置文件
配置文件目录/etc/nginx,最新版本nginx配置由4个文件构成:
文件名称 | 描述 |
---|---|
conf.d | 用户自己定义的conf配置文件 |
sites-available | 系统默认设置的配置文件 |
sites-enabled | 由sites-available 中的配置文件转换生成 |
nginx.conf | 汇总以上三个配置文件的内容,同时配置我们所需要的参数 |
/var/www/html | nginx 默认页面目录 |
默认监听端口80,默认配置文件位置在/etc/nginx/sites-available/default,在conf.d目录下创建wordpress.conf作为博客nginx的配置文件
2.安装php7.4
1.卸载已有php
sudo apt-get autoremove php*
2.添加php7.4源
sudo add-apt-repository ppa:ondrej/php && sudo apt-get update
3.安装php7.4
apt-get install php7.4
4.安装必须的扩展
sudo -y apt-get install
sudo -y apt-get install
sudo -y apt-get install php7.4-fpm php7.4-mysql php7.4-curl php7.4-json php7.4-mbstring php7.4-xml php7.4-intl php-pear php7.4-dev
5.可选扩展
sudo apt-get install php7.4-gd
sudo apt-get install php7.4-soap
sudo apt-get install php7.4-gmp
sudo apt-get install php7.4-odbc
sudo apt-get install php7.4-pspell
sudo apt-get install php7.4-bcmath
sudo apt-get install php7.4-enchant
sudo apt-get install php7.4-ldap
sudo apt-get install php7.4-opcache
sudo apt-get install php7.4-readline
sudo apt-get install php7.4-sqlite3
sudo apt-get install php7.4-xmlrpc
sudo apt-get install php7.4-bz2
sudo apt-get install php7.4-interbase
sudo apt-get install php7.4-pgsql
sudo apt-get install php7.4-recode
sudo apt-get install php7.4-sybase
sudo apt-get install php7.4-xsl
sudo apt-get install php7.4-cgi
sudo apt-get install php7.4-dba
sudo apt-get install php7.4-phpdbg
sudo apt-get install php7.4-snmp
sudo apt-get install php7.4-tidy
sudo apt-get install php7.4-zip*
3.安装mysql
1.安装命令
sudo apt-get install mysql-server
2.初始化mysql
sudo mysql_secure_installation
配置说明
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin? 是否启用插件验证密码强度
Please set the password for root here. 创建root用户密码
Remove anonymous users? (Press y|Y for Yes, any other key for No) : 是否删除匿名用户
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 是否允许root用户远程登录
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : 是否删除测试数据库并访问它
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : 重新加载表并保存配置
3.登录mysql为blog创建数据库
登录mysql
sudo mysql -uroot -p
创建数据库
#创建数据库
create database wordpress charset=utf8;
#创建独立用户
create user 'username'@'%' identified by 'password';
#为数据库添加用户
grant all privileges on wordpress.* to 'username'@'%';
4.创建nginx配置文件
vim /etc/nginx/conf.d/wordpress.conf
配置文件内容
server {
listen 443 ssl;
server_name xxx.xxx.com
server_tokens off;
root /var/www/wordpress;#网站根目录
#ssl证书配置,使用非443端口无需证书
ssl_certificate conf.d/ssl/xxxx.pem;
ssl_certificate_key conf.d/ssl/xxxx.key;
ssl_session_timeout 5m;
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 / {
root /var/www/wordpress;
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
#配置nginx解析php
location ~ \.php(.*)$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
5.配置网站目录权限并且安装bong
给网站目录赋予nginx执行用户的权限
chown -R www-data:www-data wordpress
浏览器访问nginx配置文件中的域名即可安装blog,过程中会输入创建的数据库名、用户名及密码