日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

文章目錄

  • Nginx做負載均衡服務器,配置動靜分離3. 在134主機主機部署lnmp,在動態資源4.1 在128主機安裝httpd,做靜態資源4.2 在129主機源碼安裝nginx并配置負載均衡器,進行調度5. 配置負載均衡,129主機

1. 題目:

后端RS服務器?臺部署LNMP(nginx1.22+MySQL8.0+php8.0),?臺部署
httpd。
要求nginx和php使?編譯安裝
最后要通過訪問nginx負載均衡服務器的IP看到動靜分離的效果。

2. 環境和提供軟件包

2.1 提供軟件包

[root@node6 ~]# wget https://nginx.org/download/nginx-1.22.0.tar.gz https://www.php.NET/distributions/php-8.0.23.tar.gz
[root@node6 ~]# ls
anaconda-ks.cfg                             nginx-1.22.0.tar.gz
mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz  php-8.0.23.tar.gz
[root@node6 ~]#

2.2 環境

主機

ip

安裝的服務

node6

192.168.232.134

lnmp,動態資源

node3

192.168.232.128

nginx,靜態資源

node2

192.168.232.129

nginx,做負載均衡

  • 關閉防火墻
[root@node6 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@node6 ~]# vim /etc/selinux/config 
[root@node6 ~]# setenforce 0


[root@node3 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@node3 ~]# setenforce 0
[root@node3 ~]# vi /etc/selinux/config


[root@node2 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@node2 ~]# setenforce 0
[root@node2 ~]# vi /etc/selinux/config

3. 在134主機主機部署lnmp,在動態資源

3.1 源碼安裝nginx

創建系統用戶nginx
[root@node6 ~]# useradd -r -M -s /sbin/nologin nginx
[root@node6 ~]# 


安裝依賴環境
[root@node6 ~]# yum -y groups mark install 'Development Tools'
[root@node6 ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make 


創建日志存放目錄
[root@node6 ~]# mkdir -p /var/log/nginx
[root@node6 ~]# chown -R nginx.nginx /var/log/nginx
[root@node6 ~]# ll -d /var/log/nginx
drwxr-xr-x. 2 nginx nginx 6 Sep  5 18:43 /var/log/nginx


編譯安裝
[root@node6 ~]# tar xf nginx-1.22.0.tar.gz 
[root@node6 ~]# cd nginx-1.22.0
[root@node6 nginx-1.22.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@node6 nginx-1.22.0]# make 
[root@node6 nginx-1.22.0]# make install


nginx安裝后配置
[root@node6 ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@node6 ~]# source /etc/profile.d/nginx.sh



啟動nginx
[root@node6 ~]# nginx 
[root@node6 ~]# 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           0.0.0.0:80          0.0.0.0:*            
LISTEN 0      128              [::]:22             [::]:*            
[root@node6 ~]# nginx -s stop
[root@node6 ~]# 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              [::]:22             [::]:*            
[root@node6 ~]#
  • 可以訪問

 

3.2 二進制安裝MySQL

安裝依賴包,創建用戶,并解壓
[root@node6 ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs

[root@node6 ~]# useradd -r -M -s /sbin/nologin mysql

[root@node6 ~]# tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz -C /usr/local/



修改屬主
[root@node6 ~]# cd /usr/local/
[root@node6 local]# ls
bin    include  libexec                              sbin
etc    lib      mysql-8.0.20-linux-glibc2.12-x86_64  share
games  lib64    nginx                                src
[root@node6 local]# mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql
[root@node6 local]# chown -R mysql.mysql mysql
[root@node6 local]# ll -d mysql
drwxr-xr-x. 9 mysql mysql 129 Sep  5 19:02 mysql



配置環境變量,man文檔,lib庫,頭文件
[root@node6 ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@node6 ~]# source /etc/profile.d/mysql.sh
[root@node6 ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@node6 ~]# ldconfig 
[root@node6 ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@node6 ~]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@node6 ~]# 
[root@node6 ~]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/local/mysql/man



建立數據存放目錄,并修改屬主
[root@node6 ~]# mkdir -p /opt/data
[root@node6 ~]# chown -R mysql.mysql /opt/data
[root@node6 ~]# ll -d /opt/data
drwxr-xr-x. 2 mysql mysql 6 Sep  5 19:09 /opt/data
[root@node6 ~]# 


初始化數據庫,并保存密碼
[root@node6 ~]# mysqld --initialize --user mysql --datadir /opt/data
2022-09-05T11:10:42.151293Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 209429
2022-09-05T11:10:42.160150Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-09-05T11:10:43.610708Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-09-05T11:10:44.652264Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: w-ETXrfTV1wE
[root@node6 ~]# echo 'w-ETXrfTV1wE' > passwd
[root@node6 ~]# cat passwd
w-ETXrfTV1wE
[root@node6 ~]# 



生成配置文件
[root@node6 ~]# > /etc/my.cnf
[root@node6 ~]# vim /etc/my.cnf
[root@node6 ~]# 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@node6 ~]# 



配置服務啟動腳本
[root@node6 ~]# cd /usr/local/mysql/support-files/
[root@node6 support-files]# cp mysql.server mysqld
[root@node6 support-files]# vim mysqld
basedir=/usr/local/mysql
datadir=/opt/data
[root@node6 support-files]# chown -R mysql.mysql mysqld
[root@node6 support-files]# ll -d mysqld
-rwxr-xr-x. 1 mysql mysql 10602 Sep  2 19:06 mysqld
[root@node6 support-files]# 


先啟動測試一下
[root@node6 ~]# /usr/local/mysql/support-files/mysqld start
Starting MySQL.Logging to '/opt/data/node6.err'.
 SUCCESS! 
[root@node6 ~]# 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          0.0.0.0:80           0.0.0.0:*            
LISTEN 0      128             [::]:22              [::]:*            
LISTEN 0      70                 *:33060              *:*            
LISTEN 0      128                *:3306               *:*            
[root@node6 ~]# /usr/local/mysql/support-files/mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@node6 ~]# 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           0.0.0.0:80          0.0.0.0:*            
LISTEN 0      128              [::]:22             [::]:*            
[root@node6 ~]# 


配置service文件,設置開機自啟
[root@node6 ~]# cd /usr/lib/systemd/system
[root@node6 system]# cp sshd.service mysqld.service
[root@node6 system]# ll sshd.service 
-rw-r--r--. 1 root root 456 Jul 12  2021 sshd.service
[root@node6 system]# ll mysqld.service
-rw-r--r--. 1 root root 456 Sep  5 19:15 mysqld.service
[root@node6 system]# vim mysqld.service 
[root@node6 system]# cat mysqld.service
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@node6 system]# systemctl daemon-reload


[root@node6 system]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service 鈫? /usr/lib/systemd/system/mysqld.service.
[root@node6 system]# 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          0.0.0.0:80           0.0.0.0:*            
LISTEN 0      128             [::]:22              [::]:*            
LISTEN 0      70                 *:33060              *:*            
LISTEN 0      128                *:3306               *:*            
[root@node6 system]# 



設置密碼
[root@node6 ~]# mysql -uroot -p'w-ETXrfTV1wE';

mysql> alter user 'root'@'localhost' identified by 'run123123';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@node6 ~]# mysql -uroot -p'run123123';
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> quit
Bye
[root@node6 ~]#

3.3 源碼安裝PHP

解壓
[root@node6 ~]# tar xf php-8.0.23.tar.gz

安裝依賴包
[root@node6 ~]# yum -y install 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 libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd sqlite-devel libzip-devel https://vault.centos.org/centos/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm



編譯安裝:
[root@node6 ~]# cd php-8.0.23
[root@node6 php-8.0.23]# ./configure --prefix=/usr/local/php7  
  --with-config-file-path=/etc 
  --enable-fpm 
  --enable-inline-optimization 
  --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-json 
  --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


[root@node6 php-8.0.23]# make
[root@node6 php-8.0.23]# make install


配置環境變量,lib,頭文件
[root@node6 ~]# cd /usr/local/php7/
[root@node6 php7]# ls
bin  etc  include  lib  php  sbin  var
[root@node6 php7]# echo 'export PATH=/usr/local/php7/bin:/usr/local/php7/:sbin:$PATH' > /etc/profile.d/php7.sh
[root@node6 php7]# source /etc/profile.d/php7.sh
[root@node6 php7]# 
[root@node6 php7]# ln -s /usr/local/php7/include /usr/include/php
[root@node6 php7]# 
[root@node6 php7]# vim /etc/ld.so.conf.d/php.conf
[root@node6 php7]# cat /etc/ld.so.conf.d/php.conf
/usr/local/php7/lib
[root@node6 php7]# ldconfig 

[root@node6 ~]# php -v
PHP 7.4.30 (cli) (built: Sep  2 2022 19:31:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@node6 ~]# 



配置php-fpm
[root@node6 ~]# cd php-8.0.23
[root@node6 php-8.0.23]# cp php.ini-production /etc/php.ini
[root@node6 php-8.0.23]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@node6 php-8.0.23]# chmod +x /etc/rc.d/init.d/php-fpm
[root@node6 php-8.0.23]# ll /etc/rc.d/init.d/php-fpm
-rwxr-xr-x. 1 root root 2402 Sep  5 19:56 /etc/rc.d/init.d/php-fpm
[root@node6 php-8.0.23]# 
[root@node6 php-8.0.23]# pwd
/root/php-8.0.23
[root@node6 php-8.0.23]# cd /usr/local/php7/etc/
[root@node6 etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d
[root@node6 etc]# cp php-fpm.conf.default php-fpm.conf
[root@node6 etc]# cd php-fpm.d/
[root@node6 php-fpm.d]# ls
www.conf.default
[root@node6 php-fpm.d]# cp www.conf.default www.conf
[root@node6 php-fpm.d]# 
[root@node6 php-fpm.d]# vim www.conf
listen = 127.0.0.1:9000


啟動
[root@node6 ~]# cd /etc/init.d
[root@node6 init.d]# ls
README  functions  php-fpm
[root@node6 init.d]# service php-fpm start
Starting php-fpm  done
[root@node6 init.d]# service php-fpm stop
Gracefully shutting down php-fpm . done
[root@node6 init.d]# service php-fpm start
Starting php-fpm  done
[root@node6 init.d]# 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        127.0.0.1:9000         0.0.0.0:*            
LISTEN 0      128          0.0.0.0:80           0.0.0.0:*            
LISTEN 0      128             [::]:22              [::]:*            
LISTEN 0      70                 *:33060              *:*            
LISTEN 0      128                *:3306               *:*            
[root@node6 init.d]#

3.4 配置nginx

[root@node6 ~]# cd /usr/local/nginx/conf/
[root@node6 conf]# vim nginx.conf
[root@node6 conf]# vim nginx.conf
[root@node6 conf]# cat nginx.conf

user  nginx;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  Application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.php index.html index.htm; //在index后面添加index.php,表示優先訪問php頁面
        }

        #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;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
//將以下內容取消注釋并修改    
        location ~ .php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
[root@node6 conf]# nginx -s stop
[root@node6 conf]# nginx

3.5 配置PHP網絡界面

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

重啟
[root@node6 ~]# nginx -s stop
[root@node6 ~]# nginx
  • 訪問:http://192.168.232.134/

 

4. 部署

4.1 在128主機安裝httpd,做靜態資源

[root@node3 ~]# yum -y install httpd
[root@node3 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@node3 ~]# 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             [::]:*

 

4.2 在129主機源碼安裝nginx并配置負載均衡器,進行調度

[root@node2 ~]# wget https://nginx.org/download/nginx-1.22.0.tar.gz
--2022-09-05 20:47:25--  https://nginx.org/download/nginx-1.22.0.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1073322 (1.0M) [application/octet-stream]
Saving to: 'nginx-1.22.0.tar.gz'

nginx-1.22.0.tar. 100%[==========>]   1.02M  29.1KB/s    in 20s     

2022-09-05 20:47:47 (51.5 KB/s) - 'nginx-1.22.0.tar.gz' saved [1073322/1073322]


[root@node2 ~]# useradd -r -M -s /sbin/nologin nginx
[root@node2 ~]# yum -y groups mark install 'Development Tools'
[root@node2 ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make 


[root@node2 ~]# mkdir -p /var/log/nginx
[root@node2 ~]# chown -R nginx.nginx /var/log/nginx
[root@node2 ~]# ll -d /var/log/nginx
drwxr-xr-x. 2 nginx nginx 6 Sep  5 20:51 /var/log/nginx
[root@node2 ~]# tar xf nginx-1.22.0.tar.gz 
[root@node2 ~]# cd nginx-1.22.0
[root@node2 nginx-1.22.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@node2 nginx-1.22.0]# make
[root@node2 nginx-1.22.0]# make install


[root@node2 ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@node2 ~]# source /etc/profile.d/nginx.sh


[root@node2 ~]# nginx 
[root@node2 ~]# 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           0.0.0.0:80          0.0.0.0:*            
LISTEN 0      128              [::]:22             [::]:*            
[root@node2 ~]#

5. 配置負載均衡,129主機

[root@node6 sbin]# ss -antl
State  Recv-Q Send-Q Local Address:Port    Peer Address:Port Process 
LISTEN 0      128          0.0.0.0:80           0.0.0.0:*            
LISTEN 0      128          0.0.0.0:22           0.0.0.0:*            
LISTEN 0      128        127.0.0.1:9000         0.0.0.0:*            
LISTEN 0      128             [::]:22              [::]:*            
LISTEN 0      70                 *:33060              *:*            
LISTEN 0      128                *:3306               *:*            
[root@node6 sbin]# 


[root@node2 ~]# cd /usr/local/nginx/conf/
[root@node2 conf]# vim nginx.conf



#gzip  on;

    upstream backend  #配置負載均衡
        server 192.168.232.128;
        server 192.168.232.134;
    }   

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://backend;#配置反向代理
        }

  
[root@node2 conf]# 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
[root@node2 conf]# nginx -s reload
[root@node2 conf]# nginx -s stop
[root@node2 conf]# nginx
  • 訪問:http://192.168.232.129/

 

  • 訪問:http://192.168.232.129/

 

6. 實現動靜分離

[root@node2 conf]# pwd
/usr/local/nginx/conf
[root@node2 conf]# vim nginx.conf
[root@node2 conf]# nginx -s reload
[root@node2 conf]# vim nginx.conf
[root@node2 conf]# nginx -s reload

#gzip  on;

    upstream static {
        server 192.168.232.128;#httpd主機的ip
    }

    upstream dynamic {
        server 192.168.232.134;#lnmp主機的ip
    }

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://static;#訪問靜態資源會自動跳轉到進行訪問
        }

   # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        location ~ .php$ {
            proxy_pass   http://dynamic;#訪問動態資源會自動跳轉到進行訪問
        }
[root@node2 conf]# nginx -s reload
[root@node2 conf]# 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
[root@node2 conf]#
  • 訪問靜態資源:http://192.168.232.129/

 

  • 訪問動態資源:http://192.168.232.129/index.php

 

 

分享到:
標簽:nginx
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定