nginx动静分离

nginx动静分离

nginx安装与配置

安装
关闭防火墙和selinux
[root@localhost ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0

安装epel源、vim、wget
[root@localhost ~]# yum -y install epel-release vim wget

创建系统用户nginx
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx

安装依赖环境
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@localhost ~]# yum -y groups mark install 'Development Tools'

创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx

下载nginx
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
[root@localhost src]# ls
debug  kernels  nginx-1.12.0.tar.gz
[root@localhost src]# tar xf nginx-1.12.0.tar.gz 
[root@localhost src]# cd nginx-1.12.0
[root@localhost nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.12.0]# make && make install
配置
配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# cat /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin:$PATH
[root@localhost ~]# bash

服务控制方式,使用nginx命令
    -t  //检查配置文件语法
    -v  //输出nginx的版本
    -V  //查看编译nginx时,用了哪些参数
    -c  //指定配置文件的路径
    -s  //发送服务控制信号,可选值有{stop|quit|reopen|reload}

[root@localhost ~]# nginx
[root@localhost ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:80                  *:*                  
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  

代理

[root@localhost ~]# curl -s 192.168.145.175/status |awk 'NR==4'|awk -F: {'print $4'}
 0 

[root@nginx ~]# yum -y install gcc gcc-c++ bzip2 pcre* make wget
[root@nginx ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.6.tar.gz
[root@nginx ~]# ls
公共  视频  文档  音乐  anaconda-ks.cfg       zabbix-5.4.6.tar.gz
模板  图片  下载  桌面  initial-setup-ks.cfg  zabbix-5.4.6.tar.gz.1
[root@nginx ~]# tar xf zabbix-5.4.6.tar.gz 
[root@nginx ~]# tar xf zabbix-5.4.6.tar.gz 
[root@nginx ~]# useradd -r -M -s /sbin/nologin zabbix
[root@nginx ~]# chown zabbix.zabbix zabbix-5.4.6
[root@nginx ~]# cd zabbix-5.4.6/
[root@nginx zabbix-5.4.6]# ./configure --enable-agent
[root@nginx zabbix-5.4.6]# make install

Server=192.168.145.170      修改成zabbix服务端IP
ServerActive=192.168.145.170        修改成zabbix服务端IP
Hostname=nginx      主机名
UnsafeUserParameters=1
UserParameter=status,/scripts/status.sh         添加这行指明脚本位置 

编写监控脚本
[root@nginx ~]# mkdir /scripts
[root@nginx ~]# cd /scripts/
[root@nginx scripts]# vim status.sh
[root@nginx scripts]# cat status.sh 
#!/bin/bash

status=$(curl -s 192.168.145.175/status |awk 'NR==4'|awk -F: {'print $4'})

if [ $status -ge 1 ];then
        echo "1"
else
        echo "0"
fi
[root@nginx scripts]# chmod +x status.sh 
[root@nginx scripts]# ls
status.sh

开启服务
[root@nginx ~]# zabbix_agentd 
[root@nginx ~]# ss -antl
State    Recv-Q     Send-Q          Local Address:Port          Peer Address:Port    
LISTEN   0          32              192.168.122.1:53                 0.0.0.0:*       
LISTEN   0          128                   0.0.0.0:22                 0.0.0.0:*       
LISTEN   0          5                   127.0.0.1:631                0.0.0.0:*       
LISTEN   0          128                   0.0.0.0:10050              0.0.0.0:*       
LISTEN   0          128                   0.0.0.0:111                0.0.0.0:*       
LISTEN   0          128                   0.0.0.0:80                 0.0.0.0:*       
LISTEN   0          128                      [::]:22                    [::]:*       
LISTEN   0          5                       [::1]:631                   [::]:*       
LISTEN   0          128                      [::]:111                   [::]:*      


[root@localhost ~]# zabbix_get -s 192.168.145.175 -k status
0
[root@localhost ~]# zabbix_get -s 192.168.145.175 -k status
1

LNMP

部署

关闭防火墙selinux
[root@localhost ~]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config 
[root@localhost ~]# setenforce 0
[root@localhost ~]# reboot

下载nginx、mysql、php安装包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.20.1.tar.gz
[root@localhost src]# ls
debug    mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz  php-8.0.11.tar.xz
kernels  nginx-1.20.1.tar.gz

解压
[root@localhost src]# tar xf nginx-1.20.1.tar.gz -C /usr/local/
[root@localhost src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# tar xf php-8.0.11.tar.xz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
bin  games    lib    libexec                              nginx-1.20.1  sbin   src
etc  include  lib64  mysql-5.7.34-linux-glibc2.12-x86_64  php-8.0.11    share

## 安装nginx ##
创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx

安装依赖包
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel make gcc gcc-c++
[root@localhost ~]# yum -y groups mark install 'Development Tools'

[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx

编译安装
[root@localhost ~]# cd /usr/local/nginx-1.20.1/
[root@localhost nginx-1.20.1]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.20.1]# make && make install

配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# . /etc/profile.d/nginx.sh

## 安装mysql ##
创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin  mysql

安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs

软链接
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.7.34-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.34-linux-glibc2.12-x86_64/'
[root@localhost local]# ll
总用量 4
drwxr-xr-x.  2 root root    6 8月  12 2018 bin
drwxr-xr-x.  2 root root    6 8月  12 2018 etc
drwxr-xr-x.  2 root root    6 8月  12 2018 games
drwxr-xr-x.  2 root root    6 8月  12 2018 include
drwxr-xr-x.  2 root root    6 8月  12 2018 lib
drwxr-xr-x.  2 root root    6 8月  12 2018 lib64
drwxr-xr-x.  2 root root    6 8月  12 2018 libexec
lrwxrwxrwx.  1 root root   36 10月 27 11:51 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64/
drwxr-xr-x.  9 root root  129 10月 27 11:44 mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x.  6 root root   54 10月 27 11:48 nginx
drwxr-xr-x.  9 1001 1001  186 10月 27 11:47 nginx-1.20.1
drwxrwxr-x. 16 root root 4096 9月  22 01:07 php-8.0.11
drwxr-xr-x.  2 root root    6 8月  12 2018 sbin
drwxr-xr-x.  5 root root   49 8月  24 23:44 share
drwxr-xr-x.  2 root root    6 8月  12 2018 src

修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll -d /usr/local/mysql
lrwxrwxrwx. 1 mysql mysql 36 10月 27 11:51 /usr/local/mysql -> mysql-5.7.34-linux-glibc2.12-x86_64/

配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# . /etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

创建数据存放目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2021-10-27T03:54:06.981049Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-27T03:54:07.115449Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-27T03:54:07.141771Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-27T03:54:07.196019Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 88c3820b-36d9-11ec-884f-000c29db25c6.
2021-10-27T03:54:07.199824Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-27T03:54:07.663939Z 0 [Warning] CA certificate ca.pem is self signed.
2021-10-27T03:54:08.025224Z 1 [Note] A temporary password is generated for root@localhost: pzfpjAa!p6#o

配置mysql
[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
'/usr/local/include/mysql' -> '/usr/local/mysql/include/'
[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfig

生成配置文件
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve

配置服务启动脚本
[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

配置service文件
[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# cat /usr/lib/systemd/system/mysqld.service 
[Unit]
Description=mysqld server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop

[Install]
WantedBy=multi-user.target

重新加载并启动
[root@localhost ~]# systemctl  daemon-reload
[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 

登录并更改密码
[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password = password('zs123');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit
Bye

## 安装php ##
下载依赖包
[root@localhost ~]# yum -y install sqlite-devel libzip-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel


[root@localhost ~]# cd /usr/src/
[root@localhost src]# yum install autoconf automake libtool -y
[root@localhost src]# wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
[root@localhost src]# ls
debug    mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz  oniguruma-6.9.4.tar.gz
kernels  nginx-1.20.1.tar.gz                         php-8.0.11.tar.xz
[root@localhost src]# tar xf oniguruma-6.9.4.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/oniguruma-6.9.4/
[root@localhost oniguruma-6.9.4]# ls
AUTHORS         configure.ac   INSTALL         NEWS                   src
autogen.sh      COPYING        install-sh      onig-config.in         test
ChangeLog       depcomp        m4              oniguruma.pc.cmake.in  test-driver
cmake           doc            Makefile.am     oniguruma.pc.in        windows
CMakeLists.txt  harnesses      make_win32.bat  README
compile         HISTORY        make_win64.bat  README_japanese
config.guess    index.html     make_win.bat    README.md
config.sub      index_ja.html  missing         sample
[root@localhost oniguruma-6.9.4]# ./autogen.sh && ./configure --prefix=/usr
[root@localhost oniguruma-6.9.4]# make && make install
[root@localhost php-8.0.11]#  ./configure --prefix=/usr/local/php8  \
--with-config-file-path=/etc \
--enable-fpm \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif  \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.
[root@localhost php-8.0.11]# make && make install

配置环境变量
[root@localhost php-8.0.11]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[root@localhost php-8.0.11]# source /etc/profile.d/php.sh
[root@localhost php-8.0.11]# which php
/usr/local/php8/bin/php
[root@localhost php-8.0.11]# php -v
PHP 8.0.11 (cli) (built: Oct 27 2021 12:31:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.11, Copyright (c) Zend Technologies
[root@localhost php-8.0.11]# 

配置php-fpm
[root@localhost php-8.0.11]# cp php.ini-production /etc/php.ini
cp:是否覆盖'/etc/php.ini'? y
[root@localhost php-8.0.11]# cd sapi/
[root@localhost sapi]# cp fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost sapi]# chmod +x /etc//init.d/php-fpm
[root@localhost sapi]# cd ..
[root@localhost php-8.0.11]# cd /usr/local/php8/
[root@localhost php8]# cd etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# cd
[root@localhost ~]# cp /usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/php-fpm.service
[root@localhost ~]# vim /usr/lib/systemd/system/php-fpm.service
[root@localhost ~]# cat /usr/lib/systemd/system/php-fpm.service 
[Unit]
Description=Php-fpm server daemon
After=network.target

[Service]
Type=forking
ExecStart=service php-fpm start
ExecStop=service php-fpm stop

[Install]
WantedBy=multi-user.target

重新加载
[root@localhost ~]# systemctl  daemon-reload

启动
[root@localhost ~]# cd /usr/local/php-8.0.11/
[root@localhost php-8.0.11]# service php-fpm start
Starting php-fpm  done
[root@localhost php-8.0.11]# ss -antl
State     Recv-Q     Send-Q          Local Address:Port         Peer Address:Port    
LISTEN    0          32              192.168.122.1:53                0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:22                0.0.0.0:*       
LISTEN    0          5                   127.0.0.1:631               0.0.0.0:*       
LISTEN    0          128                 127.0.0.1:9000              0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:111               0.0.0.0:*       
LISTEN    0          128                      [::]:22                   [::]:*       
LISTEN    0          5                       [::1]:631                  [::]:*       
LISTEN    0          80                          *:3306                    *:*       
LISTEN    0          128                      [::]:111                  [::]:*       


## nginx配置 ##
        location / {
            root   html;
            index  index.php index.html index.htm;

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# vim index.php
[root@localhost html]# cat index.php 
<?php
  phpinfo();
?>

重启所有服务
## php配置 ##
[root@localhost ~]# vim /usr/local/php8/etc/php-fpm.d/www.conf
user = nginx            //改为nginx
group = nginx           //改为nginx

[root@localhost ~]# nginx 
[root@localhost ~]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@localhost ~]# ss -antl
State     Recv-Q     Send-Q          Local Address:Port         Peer Address:Port    
LISTEN    0          32              192.168.122.1:53                0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:22                0.0.0.0:*       
LISTEN    0          5                   127.0.0.1:631               0.0.0.0:*       
LISTEN    0          128                 127.0.0.1:9000              0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:111               0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:80                0.0.0.0:*       
LISTEN    0          128                      [::]:22                   [::]:*       
LISTEN    0          5                       [::1]:631                  [::]:*       
LISTEN    0          80                          *:3306                    *:*       
LISTEN    0          128                      [::]:111                  [::]:*   

httpd服务

[root@localhost src]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug  httpd-2.4.48.tar.gz  kernels
[root@localhost src]# tar xf httpd-2.4.48.tar.gz 
[root@localhost src]# tar xf apr-1.7.0.tar.gz 
[root@localhost src]# tar xf apr-util-1.6.1.tar.gz 
[root@localhost src]# cd apr-1.7.0
[root@localhost apr-1.7.0]# vim configure
cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile"                注释或者删除此后


安装EPEL rpm 包
[root@localhost apr-1.7.0]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
[root@localhost apr-1.7.0]# ls /etc/yum.repos.d/
CentOS-Linux-AppStream.repo          CentOS-Linux-Plus.repo
CentOS-Linux-BaseOS.repo             CentOS-Linux-PowerTools.repo
CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-Sources.repo
CentOS-Linux-Debuginfo.repo          epel-modular.repo
CentOS-Linux-Devel.repo              epel-playground.repo
CentOS-Linux-Extras.repo             epel-testing-modular.repo
CentOS-Linux-FastTrack.repo          epel-testing.repo
CentOS-Linux-HighAvailability.repo   epel.repo
CentOS-Linux-Media.repo
[root@localhost apr-1.7.0]# yum clean all
Failed to set locale, defaulting to C.UTF-8
21 files removed
[root@localhost apr-1.7.0]# yum makecache
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream                           1.9 MB/s | 9.5 MB     00:04    
CentOS Linux 8 - BaseOS                              1.5 MB/s | 7.5 MB     00:05    
CentOS Linux 8 - Extras                              9.6 kB/s |  10 kB     00:01    
Extra Packages for Enterprise Linux Modular 8 - x86_ 333 kB/s | 955 kB     00:02    
Extra Packages for Enterprise Linux 8 - x86_64       1.6 MB/s |  11 MB     00:06    
Last metadata expiration check: 0:00:01 ago on Sun Oct 31 12:40:50 2021.
Metadata cache created.

安装开发工具包
[root@localhost apr-1.7.0]# yum groups mark install 'Development Tools' -y

创建用户
[root@localhost src]# useradd -r -M -s /sbin/nologin apache

安装依赖包
[root@localhost src]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make

编译安装
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install
root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make && make install
[root@localhost httpd-2.4.48]# ./configure --prefix=/usr/local/apache \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
[root@localhost httpd-2.4.48]# make && make install

配置
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man       添加
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
ServerName www.example.com:80       取消注释

启动apache
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   Process   
LISTEN   0        128               0.0.0.0:22              0.0.0.0:*                
LISTEN   0        128                     *:80                    *:*                
LISTEN   0        128                  [::]:22                 [::]:*         

配置开机自启
[root@localhost ~]# vim /usr/lib/systemd/system/httpd.service
[root@localhost ~]# cat /usr/lib/systemd/system/httpd.service 
[Unit]
Description=Httpd server daemon
Documentation=man:httpd(8)
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl status httpd.service
● httpd.service - Httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: di>
   Active: inactive (dead) since Sun 2021-10-31 12:56:07 EDT; 6s ago
     Docs: man:httpd(8)
  Process: 85262 ExecStop=/usr/local/apache/bin/apachectl stop (code=exited, status=>
  Process: 85258 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, statu>

Oct 31 12:56:07 localhost.localdomain systemd[1]: Starting Httpd server daemon...
Oct 31 12:56:07 localhost.localdomain apachectl[85258]: httpd (pid 79944) already ru>
Oct 31 12:56:07 localhost.localdomain systemd[1]: httpd.service: Succeeded.
Oct 31 12:56:07 localhost.localdomain systemd[1]: Started Httpd server daemon.

启用代理模块
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
#LoadModule remoteip_module modules/mod_remoteip.so
LoadModule proxy_module modules/mod_proxy.so                去掉注释
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so      去掉注释
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   Process   
LISTEN   0        128               0.0.0.0:22              0.0.0.0:*                
LISTEN   0        128                     *:80                    *:*                
LISTEN   0        128                  [::]:22                 [::]:*                

[root@lnmp ~]# nginx 
[root@lnmp ~]# systemctl start php-fpm.service
[root@lnmp ~]# systemctl start mysqld.service
[root@lnmp ~]# ss -antl
State     Recv-Q     Send-Q          Local Address:Port         Peer Address:Port    
LISTEN    0          32              192.168.122.1:53                0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:22                0.0.0.0:*       
LISTEN    0          5                   127.0.0.1:631               0.0.0.0:*       
LISTEN    0          128                 127.0.0.1:9000              0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:111               0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:80                0.0.0.0:*       
LISTEN    0          128                      [::]:22                   [::]:*       
LISTEN    0          5                       [::1]:631                  [::]:*       
LISTEN    0          80                          *:3306                    *:*       
LISTEN    0          128                      [::]:111                  [::]:*      

[root@nginx ~]# nginx 
[root@nginx ~]# ss -antl
State     Recv-Q     Send-Q          Local Address:Port         Peer Address:Port    
LISTEN    0          32              192.168.122.1:53                0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:22                0.0.0.0:*       
LISTEN    0          5                   127.0.0.1:631               0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:111               0.0.0.0:*       
LISTEN    0          128                   0.0.0.0:80                0.0.0.0:*       
LISTEN    0          128                      [::]:22                   [::]:*       
LISTEN    0          5                       [::1]:631                  [::]:*       
LISTEN    0          128                      [::]:111                  [::]:*       

[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
#gzip  on;
    upstream static {
        server 192.168.145.188;             http主机IP
    }

    upstream dynamic {
        server 192.168.145.170;             lnmp主机IP
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
           # root   html;                   注释或删除
           # index  index.html index.htm;   注释或删除
           proxy_pass http://static;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        location ~ \.php$ {                 取消注释
            proxy_pass   http://127.0.0.1;  取消注释
        }                                   取消注释
[root@nginx ~]# nginx -s reload
[root@nginx ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

 

 



posted @ 2021-11-01 01:17  Aimmi  阅读(50)  评论(0)    收藏  举报