検索
ホームページ運用・保守NginxLinux環境でNginxをインストールして使用する方法

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

Linux環境でNginxをインストールして使用する方法

##4 をインストールします。 nginx 設定ファイルは正しいです。

nginx -t

は次のように出力されます:

nginx: 設定ファイル /etc/nginx/nginx.conf の構文は ok

nginx:設定ファイル /etc/nginx /nginx.conf テストは成功しました

##5. Centos7.0 nginx は停止、起動、再起動を実現します

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 サイトの他の関連記事を参照してください。

声明
この記事は亿速云で複製されています。侵害がある場合は、admin@php.cn までご連絡ください。
Nginx vs. Apache:Webホスティングとトラフィック管理Nginx vs. Apache:Webホスティングとトラフィック管理Apr 12, 2025 am 12:04 AM

Nginxは、高い並行性と低リソース消費シナリオに適していますが、Apacheは複雑な構成と機能的拡張を必要とするシナリオに適しています。 1.Nginxは、高性能と多数の同時接続を処理することで知られています。 2。Apacheは、その安定性とリッチモジュールのサポートで知られています。選択するときは、特定のニーズに基づいて決定する必要があります。

NGINX:最新のWebアプリケーション用の汎用ツールNGINX:最新のWebアプリケーション用の汎用ツールApr 11, 2025 am 12:03 AM

nginxisentialformodernwebapplicationsdueToitsRolesasareverseproxy、loadbalancer、andwebserver、weberporformanceandscalability.1)itactsasaReverseproxy、拡張、およびパフォーマンスを強化し、パフォーマンスを強化し、積極的に積極的なものを増やします

nginx SSL/TLS構成:HTTPSでWebサイトを保護しますnginx SSL/TLS構成:HTTPSでWebサイトを保護しますApr 10, 2025 am 09:38 AM

NGINXを通じてWebサイトのセキュリティを確保するには、次の手順が必要です。1。基本的な構成を作成し、SSL証明書と秘密鍵を指定します。 2。構成を最適化し、HTTP/2を有効にし、OCSPSTAPLING。 3.証明書パスや暗号化スイートの問題などの一般的なエラーをデバッグします。 4。let'sencryptの使用やセッションの多重化など、アプリケーションのパフォーマンス最適化の提案。

Nginxインタビューの質問:DevOps/System管理インタビューをAceNginxインタビューの質問:DevOps/System管理インタビューをAceApr 09, 2025 am 12:14 AM

Nginxは、高性能のHTTPおよびリバースプロキシサーバーであり、高い並行接続の取り扱いに優れています。 1)基本的な構成:ポートを聞いて静的ファイルサービスを提供します。 2)高度な構成:逆プロキシとロードバランシングを実装します。 3)デバッグスキル:エラーログを確認し、構成ファイルをテストします。 4)パフォーマンスの最適化:GZIP圧縮を有効にし、キャッシュポリシーを調整します。

nginxキャッシュテクニック:ウェブサイトのパフォーマンスの向上nginxキャッシュテクニック:ウェブサイトのパフォーマンスの向上Apr 08, 2025 am 12:18 AM

Nginxキャッシュは、次の手順を通じてWebサイトのパフォーマンスを大幅に改善できます。1)キャッシュ領域を定義し、キャッシュパスを設定します。 2)キャッシュ有効期間を構成します。 3)異なるコンテンツに従って異なるキャッシュポリシーを設定します。 4)キャッシュストレージと負荷分散を最適化します。 5)キャッシュ効果を監視およびデバッグします。これらの方法により、Nginxキャッシュはバックエンドサーバーの圧力を軽減し、応答速度とユーザーエクスペリエンスを向上させることができます。

Dockerを使用したNginx:コンテナ化されたアプリケーションの展開とスケーリングDockerを使用したNginx:コンテナ化されたアプリケーションの展開とスケーリングApr 07, 2025 am 12:08 AM

DockerComposeを使用すると、Nginxの展開と管理が簡素化され、DockerswarmまたはKubernetesをスケーリングすることは一般的な慣行です。 1)DockerComposeを使用してNginxコンテナを定義および実行する、2)DockerswarmまたはKubernetesを介してクラスター管理と自動スケーリングを実装します。

Advanced Nginx構成:マスタリングサーバーブロックとリバースプロキシAdvanced Nginx構成:マスタリングサーバーブロックとリバースプロキシApr 06, 2025 am 12:05 AM

nginxの高度な構成は、サーバーブロックとリバースプロキシを介して実装できます。1。サーバーブロックにより、複数のWebサイトを1つの場合に実行することができます。各ブロックは個別に構成されます。 2.逆プロキシは、リクエストをバックエンドサーバーに転送して、負荷分散とキャッシュアクセラレーションを実現します。

nginxパフォーマンスチューニング:速度と低レイテンシの最適化nginxパフォーマンスチューニング:速度と低レイテンシの最適化Apr 05, 2025 am 12:08 AM

NGINXのパフォーマンスチューニングは、ワーカープロセスの数、接続プールサイズの数、GZIP圧縮とHTTP/2プロトコルの有効化、およびキャッシュとロードバランスを使用することで実現できます。 1.ワーカープロセスの数と接続プールサイズを調整します:worker_processesauto;イベント{worker_connections1024;}。 2。GZIP圧縮とhttp/2プロトコルを有効にします:http {gzipon; server {risten43sslhttp2;}}。 3。キャッシュ最適化:http {proxy_cache_path/path/to/cachelevels = 1:2k

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

EditPlus 中国語クラック版

EditPlus 中国語クラック版

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

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SecLists

SecLists

SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境