安装相关软件

  • 系统环境 ubuntu18.04
  • 安装nginx php php-fpm php-mysql
sudo apt-get install nginx php7.2 php7.2-fpm php7.2-mysql

#可能存在端口占用,如apache2则先关闭服务
# systemctl stop apache2
systemctl start nginx.service

# 查看socket文件
cat /etc/php/7.2/fpm/pool.d/www.conf |grep  'listen = '
# 默认 listen = /run/php/php7.2-fpm.sock

安装wordpress

https://cn.wordpress.org/latest-zh_CN.tar.gz

下载

tar zxvf latest-zh_CN.tar.gz -C /var/html www

配置环境

nginx

vim /etc/nginx/sites-available/www.sczhaoqi.com

## 开始
server {
          listen 80;
          server_name sczhaoqi.com www.sczhaoqi.com;
          rewrite ^(.*)$ https://$host$1 permanent;
        }	
server {
	listen 443;
        root /var/www/html;
        server_name sczhaoqi.com www.sczhaoqi.com; #填写绑定证书的域名
	ssl on;
	ssl_certificate 1_sczhaoqi.com_bundle.crt;
	ssl_certificate_key 2_sczhaoqi.com.key;
	ssl_session_timeout 5m;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
	ssl_prefer_server_ciphers on;
        location /loc {
          proxy_pass http://localhost:8080/loc;
        }
        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }
 
        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }
 
        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
            if (-f $request_filename/index.html){
                rewrite (.*) $1/index.html break;
            }
            if (-f $request_filename/index.php){
                rewrite (.*) $1/index.php;
            }
            if (!-f $request_filename){
                rewrite (.*) /index.php;
            }
        }
 
        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi.conf;
                fastcgi_intercept_errors on;
                include snippets/fastcgi-php.conf;
                include fastcgi.conf;
                include fastcgi_params;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                fastcgi_param HTTPS on; 
        }
 
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}

## 结束

ln -s /etc/nginx/sites-available/www.sczhaoqi.com www.sczhaoqi.com

重启服务

nginx -s reload

访问安装