1. centos のバージョンを確認します
cat /etc/redhat-release
2. リソース ライブラリを追加します
centos システムに nginx をインストールするには、以下を行う必要があります。まずリソース ライブラリを追加します:
vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
3. nginx
yum -y install nginx
##4 をインストールします。 nginx 設定ファイルは正しいです。
nginx -tは次のように出力されます:
nginx: 設定ファイル /etc/nginx/nginx.conf の構文は ok##5. Centos7.0 nginx は停止、起動、再起動を実現しますnginx:設定ファイル /etc/nginx /nginx.conf テストは成功しました
systemctl stop nginx.service
systemctl start nginx.service
systemctl restart nginx.service
systemctl status nginx.service
Auto -start at boot:
systemctl enable nginx.service
Cancel auto-start at boot:
systemctl disable nginx.service
6. nginx.conf の設定例
私の構成:
user nginx; worker_processes 4; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; #设定负载均衡的服务器列表 upstream pay_server { ip_hash; server 10.74.248.01:8088 max_fails=2 fail_timeout=2; server 10.74.248.02:8088 max_fails=2 fail_timeout=2; } upstream print_server { ip_hash; server 10.74.248.03:2001 max_fails=2 fail_timeout=2; server 10.74.248.04:2001 max_fails=2 fail_timeout=2; } upstream accss_door_server { ip_hash; server 10.74.248.05:2002 max_fails=2 fail_timeout=2; server 10.74.248.06:2002 max_fails=2 fail_timeout=2; } server { listen 80; server_name wab.kupu.ccoop.com.cn; location /invengo { proxy_pass http://pay_server; index index.jsp index.html index.htm; } location /invengo/epc { proxy_pass http://print_server; index index.jsp index.html index.htm; } location /invengo/print { proxy_pass http://print_server; index index.jsp index.html index.htm; } location /checkout { proxy_pass http://accss_door_server; index index.jsp index.html index.htm; } location /asset { proxy_pass http://accss_door_server; index index.jsp index.html index.htm; } }
一般的に使用される nginx.conf 構成:
user www www; worker_processes 2; error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { use epoll; worker_connections 2048; } 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 65; # gzip压缩功能设置 gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 6; gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml; gzip_vary on; # http_proxy 设置 client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 75; proxy_send_timeout 75; proxy_read_timeout 75; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_temp_path /usr/local/nginx/proxy_temp 1 2; # 设定负载均衡后台服务器列表 upstream backend { #ip_hash; server 192.168.10.100:8080 max_fails=2 fail_timeout=30s ; server 192.168.10.101:8080 max_fails=2 fail_timeout=30s ; } # 很重要的虚拟主机配置 server { listen 80; server_name itoatest.example.com; root /apps/oaapp; charset utf-8; access_log logs/host.access.log main; #对 / 所有做负载均衡+反向代理 location / { root /apps/oaapp; index index.jsp index.html index.htm; proxy_pass http://backend; proxy_redirect off; # 后端的web服务器可以通过x-forwarded-for获取用户真实ip proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; } #静态文件,nginx自己处理,不去backend请求tomcat location ~* /download/ { root /apps/oa/fs; } location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { root /apps/oaapp; expires 7d; } location /nginx_status { stub_status on; access_log off; allow 192.168.10.0/24; deny all; } location ~ ^/(web-inf)/ { deny all; } #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; } } ## 其它虚拟主机,server 指令开始 }
以上がLinux環境でNginxをインストールして使用する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

Nginxは、ファイルを提供し、トラフィックを管理するために使用できます。 1)nginxサービスの構成静的ファイル:リスニングポートとファイルディレクトリを定義します。 2)ロードバランシングとトラフィック管理を実装します。上流モジュールとキャッシュポリシーを使用して、パフォーマンスを最適化します。

Nginxは、高い並行性と静的コンテンツの処理に適していますが、Apacheは動的な内容と複雑なURL書き換えに適しています。 1.Nginxは、高い並行性に適したイベント駆動型モデルを採用しています。 2。Apacheは、動的なコンテンツに適したプロセスモデルまたはスレッドモデルを使用します。 3。NGINX構成は簡単ですが、Apache構成は複雑ですが、より柔軟です。

NginxとApacheにはそれぞれ独自の利点があり、選択は特定のニーズに依存します。 1.NGINXは、単純な展開を備えた高い並行性に適しており、構成の例には仮想ホストとリバースプロキシが含まれます。 2。Apacheは複雑な構成に適しており、展開も同様に簡単です。構成の例には、仮想ホストとURL書き換えが含まれます。

Nginxunitの目的は、Webアプリケーションの展開と管理を簡素化することです。その利点には、次のものが含まれます。1)Python、PHP、Go、Java、node.jsなどの複数のプログラミング言語をサポートします。 2)動的構成と自動リロード関数を提供します。 3)統一されたAPIを介してアプリケーションライフサイクルを管理します。 4)非同期I/Oモデルを採用して、高い並行性と負荷分散をサポートします。

Nginxは2002年に開始され、C10Kの問題を解決するためにIgorsysoevによって開発されました。 1.Nginxは、高性能の非同期アーキテクチャであり、高い並行性に適した高性能Webサーバーです。 2。システムのパフォーマンスと信頼性を向上させるために、リバースプロキシ、ロードバランス、キャッシュなどの高度な機能を提供します。 3。最適化手法には、HTTP/2とセキュリティ構成を使用した、ワーカープロセスの数の調整、GZIP圧縮の有効化が含まれます。

NginxとApacheの主なアーキテクチャの違いは、Nginxがイベント駆動型の非同期非ブロッキングモデルを採用し、Apacheはプロセスまたはスレッドモデルを使用することです。 1)nginxは、静的な内容と逆プロキシに適したイベントループとI/O多重化メカニズムを介して、高電流接続を効率的に処理します。 2)Apacheは、非常に安定しているがリソース消費量が高いマルチプロセスまたはマルチスレッドモデルを採用しており、リッチモジュールの拡張が必要なシナリオに適しています。

Nginxは、高い同時コンテンツと静的コンテンツの処理に適していますが、Apacheは複雑な構成と動的コンテンツに適しています。 1。NGINXは、交通量の多いシナリオに適した同時接続を効率的に処理しますが、動的コンテンツを処理するときは追加の構成が必要です。 2。Apacheは、複雑なニーズに適したリッチモジュールと柔軟な構成を提供しますが、並行性のパフォーマンスが低いです。

NginxとApacheにはそれぞれ独自の利点と欠点があり、選択は特定のニーズに基づいている必要があります。 1.Nginxは、非同期の非ブロッキングアーキテクチャのため、高い並行性シナリオに適しています。 2。Apacheは、モジュラー設計のため、複雑な構成を必要とする低変動シナリオに適しています。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

メモ帳++7.3.1
使いやすく無料のコードエディター

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

ホットトピック









