編譯安裝LNMP蝶押,并安裝wordpress狞悲,配置虛擬主機,www.test.com域名實現(xiàn)首頁訪問衷畦,admin.test.com域名實現(xiàn)wordpress的后臺訪問栗涂,配置nginx反向代理,實現(xiàn)域名代理本地9001端口
- 實驗環(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ù)庫及用戶名
[root@centos8-node1 ~]# 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;
[root@centos8-node1 ~]# systemctl start mariadb
nginx+php端配置:
安裝php-fpm斤程、php-mysql(新版的php需要配置yum源)
[root@node1 yum.repos.d]# 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
#如需通過網絡訪問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讀寫權限
[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ù)庫相關內容
[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');
編輯nginx配置文件
[root@node1 ~]# vim /apps/nginx/conf/nginx.conf
# 在主配置文件http下加如一下內容(獨立的配置文件便于管理及排錯)
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;
# 虛擬主機頭
server_name www.test.com;
#根目錄
root /data/wordpress;
index index.php;
# 針對php文件的fastcgi反向代理
location ~* \.php$ {
root /data/wordpress; #$document_root 調用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 調用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_admin.test.com.log access_json;
}
# 啟動服務
[root@node1 ~]# nginx
-
驗證:
客戶端訪問網站可能需要修改hosts文件
訪問首頁
www.png
訪問后臺
admin.png