博客列表 >Nginx 实践案例(源码编译安装方式):利用LNMP搭建wordpress站点

Nginx 实践案例(源码编译安装方式):利用LNMP搭建wordpress站点

哈
原创
2022年04月01日 14:51:12644浏览

镜像下载、域名解析、时间同步请点击 阿里云开源镜像站

​LNMP是Linux + Nginx + MySQL + PHP 四个系统的首字母缩写,相对于 LAMP(Linux + Apache + MySQL + PHP )来说的。曾经在虚拟主机建站界风靡一时,随着新的编程语言和容器技术、微服务等发展,慢慢没落了,尤其是PHP编程语言的使用量急剧下降了。​

​ WordPress是一款能让您建立出色网站、博客或应用程序的开源软件。它具有美观的设计,强大的功能,可以助您自由发挥心中所想。WordPress既是免费的,也是无价的​。

  1. # 本实践过程中的系统及环境描述
  2. LLinux https://mirrors.aliyun.com/centos/
  3. NNginx https://nginx.org/en/download.html
  4. MMySQL https://dev.mysql.com/downloads/mysql/
  5. PPHP http://php.net/downloads.php
  6. Wordpress https://cn.wordpress.org/latest-zh_CN.tar.gz
  7. #部署规划:
  8. 192.168.250.47Nginx php-fpm 运行web服务
  9. 192.168.250.48:运行MySQL数据库,Redis服务

1. 架构拓扑及主机说明

file

  1. # 三台主机
  2. 1 1 Linux+Nginx+PHP+WordPress (简称 LNP 服务器
  3. 主机名:LNP-Server-IP47
  4. CentOS 7.9
  5. IP:192.168.250.47
  6. 2 1 MySQL+Redis 服务器
  7. 主机名: MySQL-Redis-IP48
  8. CentOS 8.4
  9. IP:192.168.250.48/24
  10. 3 1 client主机
  11. WIN10-PC

2. 准备 MySQL 数据库

  1. # CentOS系统的优化,可以查以前的文章;按照架构图修改好主机名
  2. [root@CentOS84-IP48 ]#hostnamectl set-hostname MySQL-Redis-IP48
  3. [root@CentOS84-IP48 ]#exit
  4. # yum 安装 mysql-server 数据库
  5. [root@MySQL-Redis-IP48 ]#yum info mysql-server
  6. Last metadata expiration check: 19:31:21 ago on Mon 28 Mar 2022 02:34:38 AM CST.
  7. Available Packages
  8. Name : mysql-server
  9. Version : 8.0.26
  10. [root@MySQL-Redis-IP48 ]#yum -y install mysql-server
  11. # 启动服务并开启自启
  12. [root@MySQL-Redis-IP48 ]#systemctl enable --now mysqld
  13. # 进入数据库
  14. [root@MySQL-Redis-IP48 ]#mysql
  15. Welcome to the MySQL monitor. Commands end with ; or \g.
  16. Your MySQL connection id is 8
  17. Server version: 8.0.26 Source distribution
  18. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
  19. Oracle is a registered trademark of Oracle Corporation and/or its
  20. affiliates. Other names may be trademarks of their respective
  21. owners.
  22. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  23. # 创建 wordpress 库
  24. mysql> create database wordpress;
  25. Query OK, 1 row affected (0.00 sec)
  26. # 创建wordpress的数据库账户名和密码
  27. mysql> create user wordpress@'192.168.250.%' identified by '123456';
  28. Query OK, 0 rows affected (0.01 sec)
  29. # 数据库授权
  30. mysql> grant all on wordpress.* to wordpress@'192.168.250.%';
  31. Query OK, 0 rows affected (0.01 sec)
  32. # 本机登录并验证数据库
  33. mysql> show databases;
  34. +--------------------+
  35. | Database |
  36. +--------------------+
  37. | information_schema |
  38. | mysql |
  39. | performance_schema |
  40. | sys |
  41. | wordpress |
  42. +--------------------+
  43. 5 rows in set (0.01 sec)
  44. mysql> use wordpress
  45. Database changed
  46. mysql> show tables;
  47. Empty set (0.00 sec)
  48. mysql> quit
  49. Bye
  50. [root@MySQL-Redis-IP48 ]#

3. 网络验证MySQL服务

  1. # 通过网络在另外一台机器上登录上面建好的数据库服务器
  2. # 安装数据库客户端 mysql 包
  3. [root@CentOS84-IP172-48 ]#yum -y install mysql
  4. # 网络方式登录远程数据库
  5. [root@CentOS84-IP172-48 ]#mysql -uwordpress -p123456 -h192.168.250.48
  6. mysql: [Warning] Using a password on the command line interface can be insecure.
  7. Welcome to the MySQL monitor. Commands end with ; or \g.
  8. Your MySQL connection id is 9
  9. Server version: 8.0.26 Source distribution
  10. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
  11. Oracle is a registered trademark of Oracle Corporation and/or its
  12. affiliates. Other names may be trademarks of their respective
  13. owners.
  14. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  15. mysql> show databases;
  16. +--------------------+
  17. | Database |
  18. +--------------------+
  19. | information_schema |
  20. | wordpress |
  21. +--------------------+
  22. 2 rows in set (0.00 sec)
  23. mysql>

4. 配置 LNP 服务器

​基本任务: 编译安装和部署 php 支持 redis,并准备配置和启动服务文件,启动 php-fpm; 编译安装Nginx ,并准备配置和启动服务文件,启动Nginx​

4.1 部署php-fpm服务

  1. # 按照架构图修改好主机名
  2. [root@centos79 <sub>]# hostnamectl set-hostname LNP-Server-IP47
  3. [root@centos79 </sub>]# exit
  4. # 安装编译PHP需要的依赖包
  5. [root@lnp-server-ip47 ]# yum -y install gcc openssl-devel libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel
  6. # 下载 php-7.4.28.tar.xz 源码包
  7. [root@lnp-server-ip47 src]# wget https://www.php.net/distributions/php-7.4.28.tar.xz
  8. [root@lnp-server-ip47 src]# ll -h php-7.4.28.tar.xz
  9. -rw-r--r-- 1 root root 10M Feb 15 21:40 php-7.4.28.tar.xz
  10. # 解压源码包,进入源码包所在目录
  11. [root@lnp-server-ip47 src]# tar xf php-7.4.28.tar.xz
  12. [root@lnp-server-ip47 src]# ll
  13. total 11220
  14. drwxr-xr-x 9 1001 1001 186 Mar 28 17:06 nginx-1.20.2
  15. -rw-r--r-- 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz
  16. drwxrwxr-x 16 root root 4096 Feb 15 21:23 php-7.4.28
  17. -rw-r--r-- 1 root root 10418352 Feb 15 21:40 php-7.4.28.tar.xz
  18. # 准备编译参数
  19. [root@lnp-server-ip47 src]#cd php-7.4.28/
  20. [root@lnp-server-ip47 php-7.4.28]# ./configure --prefix=/apps/php74 --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm -enable-maintainer-zts --disable-fileinfo
  21. ....................................
  22. Thank you for using PHP. # 需要看到这个信息才算成功了
  23. # 查看cpu个数,作为编译参数CPU选项输入
  24. [root@lnp-server-ip47 nginx-1.20.2]# lscpu
  25. Architecture: x86_64
  26. CPU op-mode(s): 32-bit, 64-bit
  27. Byte Order: Little Endian
  28. CPU(s): 8
  29. On-line CPU(s) list: 0-7
  30. [root@lnp-server-ip47 php-7.4.28]#
  31. # 编译安装
  32. [root@lnp-server-ip47 php-7.4.28]# make -j 8 && make install
  33. ................... #此处删除很多屏显内容,需要看到下面成功信息再进入下一步
  34. Build complete.
  35. Don't forget to run 'make test'.
  36. Installing shared extensions: /apps/php74/lib/php/extensions/no-debug-zts-20190902/
  37. Installing PHP CLI binary: /apps/php74/bin/
  38. Installing PHP CLI man page: /apps/php74/php/man/man1/
  39. Installing PHP FPM binary: /apps/php74/sbin/
  40. Installing PHP FPM defconfig: /apps/php74/etc/
  41. Installing PHP FPM man page: /apps/php74/php/man/man8/
  42. Installing PHP FPM status page: /apps/php74/php/php/fpm/
  43. Installing phpdbg binary: /apps/php74/bin/
  44. Installing phpdbg man page: /apps/php74/php/man/man1/
  45. Installing PHP CGI binary: /apps/php74/bin/
  46. Installing PHP CGI man page: /apps/php74/php/man/man1/
  47. Installing build environment: /apps/php74/lib/php/build/
  48. Installing header files: /apps/php74/include/php/
  49. Installing helper programs: /apps/php74/bin/
  50. program: phpize
  51. program: php-config
  52. Installing man pages: /apps/php74/php/man/man1/
  53. page: phpize.1
  54. page: php-config.1
  55. /usr/local/src/php-7.4.28/build/shtool install -c ext/phar/phar.phar /apps/php74/bin/phar.phar
  56. ln -s -f phar.phar /apps/php74/bin/phar
  57. Installing PDO headers: /apps/php74/include/php/ext/pdo/
  58. ##############################################################################
  59. ## 准备 php 配置文件
  60. # 从配置文件模板复制,并进行修改
  61. [root@lnp-server-ip47 php-7.4.28]# cp /usr/local/src/php-7.4.28/php.ini-production /etc/php.ini
  62. # 进入当时编译参数内定义的目录 /apps/php74/ 从模板复制创建 php-fpm.conf
  63. [root@lnp-server-ip47 php-7.4.28]# cd /apps/php74/etc
  64. [root@lnp-server-ip47 etc]# cp php-fpm.conf.default php-fpm.conf
  65. # 进入子配置文件目录,从模板 文件创建 www.conf
  66. [root@lnp-server-ip47 etc]# cd php-fpm.d/
  67. [root@lnp-server-ip47 php-fpm.d]# cp www.conf.default www.conf
  68. [root@lnp-server-ip47 php-fpm.d]#
  69. # 按照本实践的思路修改 www.conf
  70. [root@lnp-server-ip47 php-fpm.d]# vim www.conf
  71. ;user = nobody
  72. user = www
  73. ;group = nobody
  74. group = www
  75. ;pm.status_path = /status
  76. pm.status_path = /status
  77. ;ping.path = /ping
  78. ping.path = /ping
  79. ;access.log = log/$pool.access.log
  80. access.log = log/$pool.access.log
  81. ;slowlog = log/$pool.log.slow
  82. slowlog = log/$pool.log.slow
  83. # 修改后的 www.conf 文件去除 ; 注释行的所有文件内容 供比对
  84. [root@lnp-server-ip47 php-fpm.d]# grep '^[^;]' www.conf
  85. [www]
  86. user = www
  87. group = www
  88. listen = 127.0.0.1:9000
  89. pm = dynamic
  90. pm.max_children = 5
  91. pm.start_servers = 2
  92. pm.min_spare_servers = 1
  93. pm.max_spare_servers = 3
  94. pm.status_path = /status
  95. ping.path = /ping
  96. access.log = log/$pool.access.log
  97. slowlog = log/$pool.log.slow
  98. [root@lnp-server-ip47 php-fpm.d]#
  99. # 创建 www 用户
  100. [root@lnp-server-ip47 php-fpm.d]# useradd -r -s /sbin/nologin www
  101. # 创建访问日志文件路径
  102. [root@lnp-server-ip47 php-fpm.d]# mkdir /apps/php74/log
  103. [root@lnp-server-ip47 php-fpm.d]#
  104. ##############################################################################
  105. ## 启动并验证 php-fpm 服务
  106. # 检查配置文件语法等
  107. [root@lnp-server-ip47 php-fpm.d]# /apps/php74/sbin/php-fpm -t
  108. [28-Mar-2022 18:05:51] NOTICE: configuration file /apps/php74/etc/php-fpm.conf test is successful
  109. # 准备启动服务文件
  110. [root@lnp-server-ip47 php-fpm.d]# cp /usr/local/src/php-7.4.28/sapi/fpm/php-fpm.service /usr/lib/systemd/system/
  111. # 启动并开机自启动 php-fpm
  112. [root@lnp-server-ip47 php-fpm.d]# systemctl daemon-reload
  113. [root@lnp-server-ip47 php-fpm.d]# systemctl enable --now php-fpm
  114. Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
  115. # 验证监听端口
  116. [root@lnp-server-ip47 php-fpm.d]# ss -ltn
  117. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  118. LISTEN 0 511 127.0.0.1:9000 *:*
  119. # 查看并跟踪 进程信息
  120. [root@lnp-server-ip47 php-fpm.d]# pstree -p |grep php
  121. |-php-fpm(20700)-+-php-fpm(20701)
  122. | `-php-fpm(20702)
  123. [root@lnp-server-ip47 php-fpm.d]# ps -ef |grep php
  124. root 20700 1 0 18:06 ? 00:00:00 php-fpm: master process (/apps/php74/etc/php-fpm.conf)
  125. www 20701 20700 0 18:06 ? 00:00:00 php-fpm: pool www
  126. www 20702 20700 0 18:06 ? 00:00:00 php-fpm: pool www
  127. root 20707 5036 0 18:07 pts/0 00:00:00 grep --color=auto php
  128. [root@lnp-server-ip47 php-fpm.d]#

4.2 部署 Nginx 服务

4.2.1 编译安装 nginx

  1. #### 编译安装 nginx
  2. # 准备Nginx编译安装的依赖包
  3. [root@lnp-server-ip47 <sub>]# yum -y install gcc pcre-devel openssl-devel zlib-devel
  4. # 下载 nginx 1.20.2 源码包 一般/usr/local/src/ 作为源码文件存放目录
  5. [root@lnp-server-ip47 </sub>]# cd /usr/local/src/
  6. [root@lnp-server-ip47 src]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
  7. # 解压源码包
  8. [root@lnp-server-ip47 src]# tar xf nginx-1.20.2.tar.gz
  9. [root@lnp-server-ip47 src]# ll
  10. total 1040
  11. drwxr-xr-x 8 1001 1001 158 Nov 16 22:44 nginx-1.20.2
  12. -rw-r--r-- 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz
  13. [root@lnp-server-ip47 src]#
  14. # 进入nginx-1.20.2 目录,准备编译参数
  15. [root@lnp-server-ip47 src]# cd nginx-1.20.2
  16. [root@lnp-server-ip47 nginx-1.20.2]# ./configure --prefix=/apps/nginx \
  17. > --user=www \
  18. > --group=www \
  19. > --with-http_ssl_module \
  20. > --with-http_v2_module \
  21. > --with-http_realip_module \
  22. > --with-http_stub_status_module \
  23. > --with-http_gzip_static_module \
  24. > --with-pcre \
  25. > --with-stream \
  26. > --with-stream_ssl_module \
  27. > --with-stream_realip_module
  28. [root@lnp-server-ip47 nginx-1.20.2]# make -j 8 && make install
  29. ##############################################################################
  30. # 准备服务文件并启动 nginx
  31. [root@lnp-server-ip47 nginx-1.20.2]# vim /usr/lib/systemd/system/nginx.service
  32. [root@lnp-server-ip47 nginx-1.20.2]# cat /usr/lib/systemd/system/nginx.service
  33. [Unit]
  34. Description=nginx - high performance web server
  35. Documentation=http://nginx.org/en/docs/
  36. After=network-online.target remote-fs.target nss-lookup.target
  37. Wants=network-online.target
  38. [Service]
  39. Type=forking
  40. PIDFile=/apps/nginx/run/nginx.pid
  41. ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
  42. ExecReload=/bin/kill -s HUP $MAINPID
  43. ExecStop=/bin/kill -s TERM $MAINPID
  44. [Install]
  45. WantedBy=multi-user.target
  46. [root@lnp-server-ip47 nginx-1.20.2]#
  47. # 创建目录
  48. [root@lnp-server-ip47 nginx-1.20.2]# mkdir /apps/nginx/run/
  49. # 修改配置文件
  50. [root@lnp-server-ip47 nginx-1.20.2]# vim /apps/nginx/conf/nginx.conf
  51. # 仅修改下面这行的内容
  52. pid /apps/nginx/run/nginx.pid;
  53. # 启动并开机自启服务
  54. [root@lnp-server-ip47 wordpress]# systemctl daemon-reload
  55. [root@lnp-server-ip47 wordpress]# systemctl enable --now nginx
  56. [root@lnp-server-ip47 wordpress]# ss -tln
  57. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  58. LISTEN 0 511 127.0.0.1:9000 *:*
  59. LISTEN 0 511 *:80 *:*
  60. [root@lnp-server-ip47 wordpress]#

4.2.2 配置 Nginx 支持 fastcgi

  1. ##############################################################################
  2. #### 配置 Nginx 支持 fastcgi
  3. [root@lnp-server-ip47 nginx-1.20.2]# vim /apps/nginx/conf/nginx.conf
  4. # 仅仅修改下面这些内容,其他都市默认值
  5. worker_processes auto;
  6. pid /apps/nginx/run/nginx.pid;
  7. server {
  8. listen 80;
  9. server_name blog.shone.cn;
  10. location / {
  11. root /data/nginx/wordpress;
  12. index index.php index.html index.htm;
  13. }
  14. location <sub> \.php$ {
  15. root /data/nginx/wordpress;
  16. fastcgi_pass 127.0.0.1:9000;
  17. fastcgi_index index.php;
  18. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  19. include fastcgi_params;
  20. }
  21. location </sub> ^/(ping|pm_status)$ {
  22. include fastcgi_params;
  23. fastcgi_pass 127.0.0.1:9000;
  24. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
  25. }
  26. # 通过命令筛选出有效的配置行
  27. [root@lnp-server-ip47 nginx-1.20.2]# grep -Ev '#|^$' /apps/nginx/conf/nginx.conf
  28. worker_processes auto;
  29. pid /apps/nginx/run/nginx.pid;
  30. events {
  31. worker_connections 1024;
  32. }
  33. http {
  34. include mime.types;
  35. default_type application/octet-stream;
  36. sendfile on;
  37. keepalive_timeout 65;
  38. server {
  39. listen 80;
  40. server_name blog.shone.cn; #指定域名
  41. location / {
  42. root /data/nginx/wordpress; #指定数据目录
  43. index index.php index.html index.htm; # 指定默认主页文件
  44. }
  45. error_page 500 502 503 504 /50x.html;
  46. location = /50x.html {
  47. root html;
  48. }
  49. location <sub> \.php$ { #实现php-fpm
  50. root /data/nginx/wordpress;
  51. fastcgi_pass 127.0.0.1:9000;
  52. fastcgi_index index.php;
  53. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  54. include fastcgi_params;
  55. }
  56. location </sub> ^/(ping|pm_status)$ { #PHP检测状态页
  57. include fastcgi_params;
  58. fastcgi_pass 127.0.0.1:9000;
  59. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
  60. }
  61. }
  62. }
  63. [root@lnp-server-ip47 nginx-1.20.2]#
  64. # 重新启动 nginx 让新配置文件生效
  65. [root@lnp-server-ip47 php-fpm.d]# systemctl reload nginx
  66. [root@lnp-server-ip47 php-fpm.d]# ss -ltn
  67. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  68. LISTEN 0 511 127.0.0.1:9000 *:*
  69. LISTEN 0 511 *:80 *:*
  70. [root@lnp-server-ip47 php-fpm.d]#

4.2.3 测试PHP工作是否正常

准备测试页面

  1. [root@lnp-server-ip47 php-fpm.d]# mkdir -p /data/nginx/wordpress
  2. [root@lnp-server-ip47 php-fpm.d]# vim /data/nginx/wordpress/phpinfo.php
  3. [root@lnp-server-ip47 php-fpm.d]# cat /data/nginx/wordpress/phpinfo.php
  4. <?php
  5. phpinfo();
  6. ?>

测试PHP的ping

file

查看状态页

file

5. 部署 WordPress

5.1 准备 WordPress 文件

  1. # 下载源文件,并复制到前面定义的网页目录下,并修改权属
  2. [root@lnp-server-ip47 <sub>]# wget https://cn.wordpress.org/latest-zh_CN.tar.gz
  3. [root@lnp-server-ip47 </sub>]# ll
  4. total 19012
  5. -rw-r--r-- 1 root root 19462197 Mar 19 00:00 latest-zh_CN.tar.gz
  6. [root@lnp-server-ip47 <sub>]# tar xf latest-zh_CN.tar.gz
  7. [root@lnp-server-ip47 </sub>]# ll
  8. total 19016
  9. -rw-r--r-- 1 root root 19462197 Mar 19 00:00 latest-zh_CN.tar.gz
  10. drwxr-xr-x 5 1006 1006 4096 Mar 19 00:00 wordpress
  11. [root@lnp-server-ip47 <sub>]# cp -r wordpress/* /data/nginx/wordpress
  12. [root@lnp-server-ip47 </sub>]# chown -R www.www /data/nginx/wordpress/
  13. [root@lnp-server-ip47 ~]#

5.2 初始化 WordPress

  1. # 修改WIN10的本地hosts文件,路径为 C:\Windows\System32\drivers\etc\hosts 在最后添加一行
  2. 192.168.250.47 blog.shone.cn
  3. 在浏览器内输入 blog.shone.cn 出现可道云的初始化向导,按照向导完成初始化

在浏览器内输入 http://blog.shone.cn

file

file

file

file

file

file

file

file

6. 优化 WordPress

6.1 允许上传大文件

  1. #注意:默认只支持1M以下文件上传,要利用php程序上传大文件,需要修改下面的配置,最大上传由下列项值的最小值决定,直接上传大于1M文件,会出现下面413错误
  2. [root@lnp-server-ip47 wordpress]# vim /apps/nginx/conf/nginx.conf
  3. http {
  4. include mime.types;
  5. default_type application/octet-stream;
  6. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  7. # '$status $body_bytes_sent "$http_referer" '
  8. # '"$http_user_agent" "$http_x_forwarded_for"';
  9. #access_log logs/access.log main;
  10. client_max_body_size 100m; #nginx上传文件大小修改成100M,默认1M
  11. .........
  12. [root@lnp-server-ip47 wordpress]# vim /etc/php.ini
  13. ; http://php.net/post-max-size
  14. ;post_max_size = 8M # 默认值为8M
  15. post_max_size = 30M
  16. ;upload_max_filesize = 2M # 默认值为2M
  17. upload_max_filesize = 20M
  18. [root@lnp-server-ip47 wordpress]# systemctl restart nginx php-fpm

6.2 安全加固

  1. # 关闭版本显示
  2. [root@lnp-server-ip47 wordpress]# grep -Ev '#|^$' /apps/nginx/conf/nginx.conf
  3. worker_processes auto;
  4. pid /apps/nginx/run/nginx.pid;
  5. events {
  6. worker_connections 1024;
  7. }
  8. http {
  9. include mime.types;
  10. default_type application/octet-stream;
  11. client_max_body_size 100m;
  12. sendfile on;
  13. keepalive_timeout 65;
  14. server {
  15. listen 80;
  16. server_name blog.shone.cn;
  17. server_tokens off; # 安全加固选项
  18. location / {
  19. root /data/nginx/wordpress;
  20. index index.php index.html index.htm;
  21. }
  22. error_page 500 502 503 504 /50x.html;
  23. location = /50x.html {
  24. root html;
  25. }
  26. location <sub> \.php$ {
  27. root /data/nginx/wordpress;
  28. fastcgi_pass 127.0.0.1:9000;
  29. fastcgi_index index.php;
  30. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  31. include fastcgi_params;
  32. fastcgi_hide_header X-Powered-By; # 安全加固选项
  33. }
  34. location </sub> ^/(ping|pm_status)$ {
  35. include fastcgi_params;
  36. fastcgi_pass 127.0.0.1:9000;
  37. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
  38. }
  39. }
  40. }
  41. [root@lnp-server-ip47 wordpress]#
  42. # 关闭 PHP版本暴露
  43. [root@lnp-server-ip47 wordpress]# vim /etc/php.ini
  44. ; http://php.net/expose-php
  45. ;expose_php = On # 默认值为ON 可以在客户端看到版本信息
  46. expose_php = Off

file

6.3 配置 php 开启 opcache 加速

  1. [root@lnp-server-ip47 wordpress]# vim /etc/php.ini
  2. .....................
  3. [opcache]
  4. ; Determines if Zend OPCache is enabled
  5. zend_extension=opcache.so
  6. opcache.enable=1
  7. .......................
  8. [root@lnp-server-ip47 wordpress]#systemctl restart php-fpm

本文转自:https://blog.51cto.com/shone/5165650

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议