この記事では、nginxが動的と静的の分離を実現する方法の例を主に紹介しており、学習価値があります。詳細は次のとおりです。 環境:
3つのホストのファイアウォールを無効にする [root@server1 ~]# systemctl stop ファイアウォールd [root@server1 ~]# systemctl ファイアウォールを無効にする [root@server1 ~]# vim /etc/selinux/config SELINUX=無効 server1にnginxをデプロイする[root@server1 opt]# cat nginx.sh #!/bin/bash [ $UID -ne 0 ]の場合 echo "管理者アカウントを使用してください" 出口 フィ app_a=nginx-1.20.1.tar.gz dir_a = /usr/local ディレクトリ dir_b = /var/log dir_c = nginx-1.20.1 です if [ ! -d $dir_b/nginx ];その後 mkdir -p $dir_b/nginx フィ chown -R nginx.nginx $dir_b/nginx yum -y インストール pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make yum -y groups mark install '開発ツール' id nginx &>/dev/null [ $? -ne 0 ]の場合; ユーザー追加 -r -M -s /sbin/nologin nginx フィ tar xf bag/$app_a -C $dir_a $dir_a/$dir_c に移動 if [ ! -d $dir_a/nginx ];その後 ./configure \ --prefix=$dir_a/nginx \ --user=nginx \ --group=nginx \ --デバッグあり\ --http_ssl_module \ で始まる --http_realip_module \ で始まる --http_image_filter_module \ で始まる --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --http-log-path=$dir_b/nginx/access.log \ --error-log-path=$dir_b/nginx/error.log && make && make install フィ CD .. if [ ! -f /etc/profile.d/nginx.sh ];then echo "エクスポート PATH=$dir_a/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh フィ cat > /usr/lib/systemd/system/nginx.service << EOF [ユニット] 説明=Nginx サーバーデーモン 欲しいもの=sshd-keygen.target [サービス] タイプ=フォーク ExecStart=$dir_a/nginx/sbin/nginx ExecStop=$dir_a/nginx/sbin/nginx -s stop ExecReload=/bin/kill -HUP $MAINPID [インストール] WantedBy=マルチユーザー.ターゲット 終了 systemctlデーモンリロード systemctl enable --now nginx ポートの表示 [root@server1 ~]# ss -antl 状態 受信Q 送信Q ローカルアドレス:ポート ピアアドレス:ポート 聞く 0 128 0.0.0.0:22 0.0.0.0:* 聞く 0 128 0.0.0.0:80 0.0.0.0:* 聞く 0 128 [::]:22 [::]:* ページを訪問 サーバーにlnmpを展開するnginxをデプロイする [root@server2 lnmp]# cat install.sh #!/bin/bash [ $UID -ne 0 ]の場合 echo "管理者アカウントを使用してください" 出口 フィ app_a=nginx-1.20.1.tar.gz dir_a = /usr/local ディレクトリ dir_b = /var/log dir_c = nginx-1.20.1 です。 if [ ! -d $dir_b/nginx ];その後 mkdir -p $dir_b/nginx フィ chown -R nginx.nginx $dir_b/nginx yum -y インストール pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make yum -y groups mark install '開発ツール' id nginx &>/dev/null [ $? -ne 0 ]の場合; ユーザー追加 -r -M -s /sbin/nologin nginx フィ tar xf bag/$app_a -C $dir_a $dir_a/$dir_c に移動 if [ ! -d $dir_a/nginx ];その後 ./configure \ --prefix=$dir_a/nginx \ --user=nginx \ --group=nginx \ --デバッグあり\ --http_ssl_module \ で始まる --http_realip_module \ で始まる --http_image_filter_module \ で始まる --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --http-log-path=$dir_b/nginx/access.log \ --error-log-path=$dir_b/nginx/error.log && make && make install フィ CD .. if [ ! -f /etc/profile.d/nginx.sh ];then echo "エクスポート PATH=$dir_a/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh フィ cat > /usr/lib/systemd/system/nginx.service << EOF [ユニット] 説明=Nginx サーバーデーモン 欲しいもの=sshd-keygen.target [サービス] タイプ=フォーク ExecStart=$dir_a/nginx/sbin/nginx ExecStop=$dir_a/nginx/sbin/nginx -s stop ExecReload=/bin/kill -HUP $MAINPID [インストール] WantedBy=マルチユーザー.ターゲット 終了 systemctlデーモンリロード systemctl enable --now nginx MySQLをデプロイする [root@server2 lnmp]# cat mysql.sh #!/bin/bash [ $UID -ne 0 ]の場合 「ルート?」をエコーします。 出口 フィ dir_a = /usr/local ディレクトリ dir_b=/opt/データ app_a=mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz app_b = mysql-5.7.34-linux-glibc2.12-x86_64 です。 id mysql &>/dev/null [ $? -ne 0 ]の場合; ユーザー追加 -r -M -s /sbin/nologin mysql フィ yum -y インストール ncurses-compat-libs ncurses-devel openssl-devel openssl cmake mariadb-devel if [ ! -d $dir_a/$app_b ];then tar xf bag/$app_a -C $dir_a フィ if [ ! -d $dir_a/mysql ];その後 ln -sv $dir_a/$app_b $dir_a/mysql フィ chown -R mysql:mysql $dir_a/mysql* echo "エクスポート PATH=$dir_a/mysql/bin:\$PATH" > /etc/profile.d/mysql.sh ソース /etc/profile.d/mysql.sh if [ ! -d /$dir_b ];その後 mkdir -p /$dir_b chown -R mysql.mysql /$dir_b フィ コンテンツ=$(ls $dir_b | wc -l) [ $content -eq 0 ]の場合 mysqld --initialize-insecure --user mysql --datadir $dir_b フィ cat > /etc/my.cnf <<EOF [mysqld] ベースディレクトリ = $dir_a/mysql データディレクトリ = $dir_b ソケット = /tmp/mysql.sock ポート = 3306 pid ファイル = $dir_b/mysql.pid ユーザー = mysql 名前解決をスキップ 終了 sed -ri "s#^(basedir=).*#\1$dir_a/mysql#g" $dir_a/mysql/support-files/mysql.server sed -ri "s#^(datadir=).*#\1$dir_b#g" $dir_a/mysql/support-files/mysql.server cat > /usr/lib/systemd/system/mysqld.service <<EOF [ユニット] 説明=mysql サーバーデーモン 後=ネットワーク.ターゲット [サービス] タイプ=フォーク ExecStart=$dir_a/mysql/support-files/mysql.server を起動します ExecStop=$dir_a/mysql/support-files/mysql.server を停止します ExecReload=/bin/kill -HUP $MAINPID [インストール] WantedBy=マルチユーザー.ターゲット 終了 systemctlデーモンリロード systemctl enable --now mysqld PHPをデプロイする php-8.0.10 の最新版をダウンロードしてください。 解凍 [root@server2 ~]# tar -xf php-8.0.10.tar.gz -C /usr/local/ 依存パッケージをインストールする [root@server2 ~]# wget http://mirrors.aliyun.com/repo/epel-7.repo [root@server1 ~]# 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 libsqlite3x-devel libzip-devel [root@server2 ~]# yum -y インストール http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm コンパイルしてインストールする [root@server2 ~]# cd /usr/local/php-8.0.10/ [root@server2 php-8.0.10]# ./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 ...... ...... ...... config.status: ext/phar/phar.phar.1 を作成しています config.status: main/php_config.h を作成しています config.status: デフォルトコマンドを実行 +--------------------------------------------------------------------+ | ライセンス: | | このソフトウェアは、こちらで入手可能な PHP ライセンスの対象です | | LICENSE ファイル内の配布。このインストールを続行すると、| | プロセスを実行する場合、お客様はこのライセンス契約の条件に拘束されます。 | | このライセンスの条件に同意しない場合は、中止する必要があります | | この時点でインストール プロセスは終了します。 | +--------------------------------------------------------------------+ PHPをご利用いただきありがとうございます。 [root@server2 php-8.0.10]# 作成 ....... ....... ....... 逆正規表現 株式会社ファルコマンド 株式会社 ビルドが完了しました。 「make test」を実行することを忘れないでください。 [root@server2 php-8.0.10]# インストールする ...... ...... /root/php-8.0.10/build/shtool インストール -c ext/phar/phar.phar /usr/local/php8/bin/phar.phar ln -s -f phar.phar /usr/local/php8/bin/phar PDO ヘッダーのインストール: /usr/local/php8/include/php/ext/pdo/ php-fpm を設定する [root@server2 php-8.0.10]# cp /etc/php.ini /opt/ [root@server2 php-8.0.10]# cp php.ini-production /etc/php.ini cp: '/etc/php.ini' を上書きしますか? y [root@server2 php-8.0.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@server2 php-8.0.10]# chmod +x /etc/init.d/php-fpm [root@server2 php-8.0.10]# cd .. [root@server2 ローカル]# cd php8/ [root@server2 php8]# cd etc/ [root@server2 など]# cp php-fpm.conf.default php-fpm.conf [root@server2 など]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf [root@server2 など]# cd php-fpm.d [root@server2 php-fpm.d]# ls www.conf www.conf.default 環境変数の設定 [root@server2 ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh [root@server2 ~]# cat /etc/profile.d/php.sh PATH=/usr/local/php8/bin:$PATH をエクスポートします [root@server2 ~]# ソース /etc/profile.d/php.sh [root@server2 ~]# どのphp php8 のbinディレクトリにphpファイルがあります。 サービスファイルの書き込み [root@server2 ~]# cat /usr/lib/systemd/system/php-fpm.service [ユニット] 説明=php-fpm サーバーデーモン 後=ネットワーク.ターゲット [サービス] タイプ=フォーク ExecStart=/etc/init.d/php-fpm 開始 ExecStop=/etc/init.d/php-fpm を停止します ExecReload=/bin/kill -HUP $MAINPID [インストール] [root@server2]# systemctlデーモンリロード PHPを起動する [root@server2 ~]# systemctl php-fpm を起動します [root@server2 ~]# ss -antl 状態 受信Q 送信Q ローカルアドレス:ポート ピアアドレス:ポート 聞く 0 128 127.0.0.1:9000 0.0.0.0:* 聞く 0 128 0.0.0.0:80 0.0.0.0:* 聞く 0 128 0.0.0.0:22 0.0.0.0:* 聞く 0 80 *:3306 *:* 聞く 0 128 [::]:22 [::]:* nginx.confで仮想ホストを設定する [root@server2 ~]# cd /usr/local/nginx/html/ [root@server2 html]# ls 50x.html インデックス.html [root@server2 html]# vim index.php [root@server2 html]# cat index.php <?php phpinfo(); ?> [root@server2 conf]# pwd ローカル [root@server2 conf]# vim nginx.conf ........ http { mime.types を含めます。 デフォルトタイプ アプリケーション/オクテットストリーム; 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 ログ/access.log メイン; ファイル送信オン; ...... 位置 / { ルートhtml; インデックス index.php index.html index.htm; } ..... 場所 ~ \.php$ { ルートhtml; 127.0.0.1:9000; をデフォルトとして設定します。 fastcgi_index インデックス.php; fastcgi_param SCRIPT_FILENAME $Document_root$fastcgi_script_name; fastcgi_params を含めます。 } [root@server2 conf]# nginx -s reload アクセス ノード3にhttpdをデプロイする[root@node3 ~]# yum -y httpdをインストールします 起動する [root@node3 ~]# systemctl httpdを起動します [root@node3 ~]# ss -antl 状態 受信Q 送信Q ローカルアドレス:ポート ピアアドレス:ポート 聞く 0 128 *:22 *:* 聞く 0 100 127.0.0.1:25 *:* 聞く 0 128 :::80 :::* 聞く 0 128 :::22 :::* 聞く 0 100 ::1:25 :::* アクセス 個別のデプロイメントの実装server1のnginx.confで設定する [root@server1 ~]# cat /usr/local/nginx/conf/nginx.conf #ユーザーnobody; ワーカープロセス 1; #error_log ログ/error.log; #error_log ログ/error.log 通知; #error_log ログ/error.log 情報; #pid ログ/nginx.pid; イベント { ワーカー接続 1024; } http { mime.types を含めます。 デフォルトタイプ アプリケーション/オクテットストリーム; #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 ログ/access.log メイン; ファイル送信オン; #tcp_nopush オン; #キープアライブタイムアウト 0; キープアライブタイムアウト65; #gzip オン; アップストリーム cm { #静的リソースアドレス サーバー 192.168.244.142; } アップストリーム nm { #動的リソースアドレス サーバー 192.168.244.133; } サーバー{ 聞く 80; server_name ローカルホスト; #文字セット koi8-r; #access_log ログ/host.access.log メイン; 位置 / { proxy_pass http://cm; #静的を指す} #エラーページ 404 /404.html; # サーバーのエラーページを静的ページ /50x.html にリダイレクトします # エラーページ 500 502 503 504 /50x.html; 場所 = /50x.html { ルートhtml; } # PHP スクリプトを 127.0.0.1:80 で listen している Apache にプロキシします # location ~ \.php$ { # 動的 proxy_pass http://nm を参照します。 } [root@server1 ~]# nginx -s リロード 192.168.244.131 にアクセスしてください 192.168.244.131/index.phpにアクセスする場合 nginx で動的と静的の分離を実現する例についての記事はこれで終わりです。nginx での動的と静的の分離に関するより関連性の高いコンテンツについては、123WORDPRESS.COM で以前の記事を検索するか、以下の関連記事を引き続き参照してください。今後とも 123WORDPRESS.COM をよろしくお願いいたします。 以下もご興味があるかもしれません:
|
<<: ハイパーリンクの幅と高さを直接設定できない問題の解決策
序文ストレス テスト中に、リソース使用のボトルネックによって発生する最も直接的なパフォーマンスの問題...
この記事では、例を使用して MySQL 変数の使用方法を説明します。ご参考までに、詳細は以下の通りで...
目次序文根拠手順1. CDから仮想マシンを起動する2. GPartedツールを使用してパーティション...
序文最近、仮想マシンを使用して Ubuntu 18.04 をインストールしました。クローン作成後、I...
目次バージョンノートプロジェクトを作成する依存関係をインストールするコンテンツの記入src/serv...
編集者は最近、macOS システムを使い始めたかったので、VMware に macOS イメージ シ...
問題の説明プラグインをインストールした後、ES7 React/Redux/GraphQL/React...
この記事では、Docker コマンドの使用とインストールについては説明しません。Docker を基礎...
Web ページでは、基本的に <input type="file">...
無料のパブリック STUN サーバーSIP 端末がプライベート IP アドレスを使用する場合、スタン...
<br />どの家庭にもそれぞれの問題があり、改訂はどの IT 企業にとっても問題の 1...
MyBatisインターセプターのページング機能を実装する方法序文:まず、実装原則についてお話しします...
この記事では、ランダムロールコールを実装するためのjsの具体的なコードを参考までに共有します。具体的...
apk add ansible を使用して、alpine イメージに ansible サービスを追加...
コードをコピーコードは次のとおりです。 .sugLayerDiv{位置:相対; overflow:h...