- 實驗環(huán)境
| 主機 | os | 軟件 | ip |
|---|---|---|---|
| mysql服務端 | centos8.1 | mariadb-server | 172.16.2.135 |
| nginx+php服務端 | centos7.6 | nginx1.16(編譯安裝) php-fpm php-mysql | 172.16.2.131 |
- mysql服務端配置:
安裝mariadb服務,創(chuàng)建wordpress所需數(shù)據(jù)庫及用戶名
yum install -y mariadb-server
[root@centos8-node1 ~]# mysql
MariaDB [(none)]> grant all on wordpress.* to wordpress@'172.16.2.%' identified by '123456';
MariaDB [(none)]> flush privileges;
nginx+php端配置:
安裝php-fpm、php-mysql(新版的php需要配置yum源)
yum install -y php74-php-fpm php74-php-mysql
編輯php配置文件
# 新建nginx系統(tǒng)用戶
[root@node1 yum.repos.d]# groupadd -r nginx
[root@node1 yum.repos.d]# useradd -r -g nginx -s /sbin/nologin nginx
# 編輯php配置文件
[root@node1 yum.repos.d]# vim /etc/opt/remi/php74/php-fpm.d/www.conf
# 修改組和用戶
user = nginx
group = nginx
#修改偵聽地址及端口
listen = 127.0.0.1:9001
#如需通過網(wǎng)絡訪問php服務可以注釋一下選項
;listen.allowed_clients = 127.0.0.1
啟動服務
[root@node1 yum.repos.d]# systemctl start php74-php-fpm.service
編譯安裝nginx
[root@node1 ~]# yum install gcc pcre-devel openssl-devel zlib-devel
[root@node1 ~]# tar xvf nginx-1.16.1.tar.gz
[root@node1 ~]# cd nginx-1.16.1/
[root@node1 ~]# ./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@node1 ~]# make -j 2 && make install
準備wordpress
[root@node1 ~]# tar xvf wordpress-4.7.4-zh_CN.tar.gz
[root@node1 ~]# mkdir /data
[root@node1 ~]# mv wordpress /data/
# 給予nginx讀寫權(quán)限
[root@node1 ~]# setfacl -R -m u:nginx:rwx /data/wordpress
[root@node1 ~]# mv /data/wordpress/wp-config-sample.php /data/wordpress/wp-config.php
# 修改配置文件里數(shù)據(jù)庫相關內(nèi)容
[root@node1 ~]# vim /data/wordpress/wp-config.php
// ** MySQL 設置 - 具體信息來自您正在使用的主機 ** //
/** WordPress數(shù)據(jù)庫的名稱 */
define('DB_NAME', 'wordpress');
/** MySQL數(shù)據(jù)庫用戶名 */
define('DB_USER', 'wordpress');
/** MySQL數(shù)據(jù)庫密碼 */
define('DB_PASSWORD', '123456');
/** MySQL主機 */
define('DB_HOST', '172.16.2.135');
準備自簽證書
[root@node1 certs]# cd /etc/pki/tls/certs/
[root@node1 certs]# make www.test.com.crt
umask 77 ; \
/usr/bin/openssl genrsa -aes128 2048 > www.test.com.key
Generating RSA private key, 2048 bit long modulus
.......+++
.....................................................................+++
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
umask 77 ; \
/usr/bin/openssl req -utf8 -new -key test.key -x509 -days 365 -out test.crt
Enter pass phrase for test.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Shanghai
Locality Name (eg, city) [Default City]:Shanghai
Organization Name (eg, company) [Default Company Ltd]:test
Organizational Unit Name (eg, section) []:test
Common Name (eg, your name or your server's hostname) []:www.test.com //此處是網(wǎng)站域名
Email Address []:
[root@node1 nginx]# mkdir /apps/nginx/ssl
[root@node1 nginx]# mv /etc/pki/tls/certs/www.test.com* /apps/nginx/ssl/
新建錯誤頁面
[root@node1 ~]# mkdir /apps/nginx/error
[root@node1 error]# vim /apps/nginx/error/error.html
這是一個自定義錯誤頁面
編輯nginx配置文件
[root@node1 ~]# vim /apps/nginx/conf/nginx.conf
# 在主配置文件http下加如一下內(nèi)容(獨立的配置文件便于管理及排錯)
include /apps/nginx/conf.d/*.conf;
# 編輯獨立配置文件
[root@node1 ~]# vim /apps/nginx/conf.d/wordpress.conf
# 定義json日志格式
log_format access_json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"uri":"$uri",'
'"domain":"$host",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"tcp_xff":"$proxy_protocol_addr",'
'"http_user_agent":"$http_user_agent",'
'"status":"$status"}';
# 配置虛擬主機
server {
# 監(jiān)聽端口
listen 80;
# 開啟https
listen 443 ssl;
# ssl on;
# 指定ssl證書
ssl_certificate /apps/nginx/ssl/www.test.com.crt;
ssl_certificate_key /apps/nginx/ssl/www.test.com.key;
# 指定ssl緩存時間
ssl_session_cache shared:sslcache:20m;
ssl_session_timeout 10m;
# 虛擬主機頭
server_name www.test.com;
#根目錄
root /data/wordpress;
index index.php;
charset utf-8;
# 針對php文件的fastcgi反向代理
location ~* \.php$ {
root /data/wordpress; #$document_root 調(diào)用root目錄
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /data/wordpress$fastcgi_script_name;
#如果SCRIPT_FILENAME是絕對路徑,則可以省略root /data/php;
include fastcgi_params;
}
# 自定義訪問日志
access_log /apps/nginx/logs/access_test.com.log access_json;
}
server {
listen 80;
server_name admin.test.com;
root /data/wordpress/wp-admin;
index index.php;
location ~* \.php$ {
root /data/wordpress/wp-admin; #$document_root 調(diào)用root目錄
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /data/wordpress$fastcgi_script_name;
#如果SCRIPT_FILENAME是絕對路徑,則可以省略root /data/php;
include fastcgi_params;
}
# 自定義錯誤頁面
error_page 500 502 503 504 404 /error.html;
location = /error.html {
root /apps/nginx/error;
}
access_log /apps/nginx/logs/access_admin.test.com.log access_json;
}
# 啟動服務
[root@node1 ~]# nginx
-
驗證:
客戶端訪問網(wǎng)站可能需要修改hosts文件
訪問首頁
image
訪問后臺

image
訪問自定義錯誤頁面

image.png
用https訪問網(wǎng)站

image.png
