ホームページ 運用・保守 Nginx CentOS7 Docker Nginx の導入と実行例の分析

CentOS7 Docker Nginx の導入と実行例の分析

May 14, 2023 pm 05:10 PM
docker nginx centos7

1. リソースの準備

dockerfile

# "ported" by adam miller <maxamillion@fedoraproject.org> from 
#  https://github.com/fedora-cloud/fedora-dockerfiles 
# 
# originally written for fedora-dockerfiles by 
#  scollier <scollier@redhat.com> 
 
from centos:centos7 
maintainer the centos project <cloud-ops@centos.org> 
 
run yum -y update; yum clean all 
run yum -y install epel-release tar ; yum clean all 
run yum -y install nginx ; yum clean all 
add nginx.conf /opt/deploy/nginx/nginx.conf 
run echo "daemon off;" >> /opt/deploy/nginx/nginx.conf 
#run curl https://git.centos.org/sources/httpd/c7/acf5cccf4afaecf3afeb18c50ae59fd5c6504910 \ 
#  | tar -xz -c /usr/local/nginx/html \ 
#  --strip-components=1 
#run sed -i -e &#39;s/apache/nginx/g&#39; -e &#39;/apache_pb.gif/d&#39; \  
#  /usr/local/nginx/html/index.html 
 
expose 80 
 
#cmd [ "/usr/local/nginx/sbin" ]
ログイン後にコピー

注: パスはシステム上に存在し、

nginx.conf ファイルに対応する必要があります

# for more information on configuration, see: 
#  * official english documentation: http://nginx.org/en/docs/ 
#  * official russian documentation: http://nginx.org/ru/docs/ 
 
user nginx; 
worker_processes 1; 
 
error_log /usr/logs/nginx/error.log; 
#error_log /var/log/nginx/error.log notice; 
#error_log /var/log/nginx/error.log info; 
 
pid    /run/nginx.pid; 
 
 
events { 
  worker_connections 1024; 
} 
 
 
http { 
  include    mime.types; 
  default_type application/octet-stream; 
 
  log_format main &#39;$remote_addr - $remote_user [$time_local] "$request" &#39; 
           &#39;$status $body_bytes_sent "$http_referer" &#39; 
           &#39;"$http_user_agent" "$http_x_forwarded_for"&#39;; 
 
  access_log /usr/logs/nginx/access.log main; 
 
  sendfile    on; 
  #tcp_nopush   on; 
 
  #keepalive_timeout 0; 
  keepalive_timeout 65; 
 
  #gzip on; 
 
  # load modular configuration files from the /etc/nginx/conf.d directory. 
  # see http://nginx.org/en/docs/ngx_core_module.html#include 
  # for more information. 
  #include /etc/nginx/conf.d/*.conf; 
 
  index  index.html index.htm; 
 
  server { 
    listen    80; 
    server_name localhost; 
    root     /usr/share/nginx/html; 
 
    #charset koi8-r; 
 
    #access_log /var/log/nginx/host.access.log main; 
 
    location / { 
      autoindex on; 
    } 
 
    # redirect server error pages to the static page /40x.html 
    # 
    error_page 404       /404.html; 
    location = /40x.html { 
    } 
 
    # redirect server error pages to the static page /50x.html 
    # 
    error_page  500 502 503 504 /50x.html; 
    location = /50x.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 /scripts$fastcgi_script_name; 
    #  include    fastcgi_params; 
    #} 
 
    # deny access to .htaccess files, if apache&#39;s document root 
    # concurs with nginx&#39;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; 
  #  root     html; 
 
  #  location / { 
  #  } 
  #} 
 
 
  # https server 
  # 
  #server { 
  #  listen    443; 
  #  server_name localhost; 
  #  root     html; 
 
  #  ssl         on; 
  #  ssl_certificate   cert.pem; 
  #  ssl_certificate_key cert.key; 
 
  #  ssl_session_timeout 5m; 
 
  #  ssl_protocols sslv2 sslv3 tlsv1; 
  #  ssl_ciphers high:!anull:!md5; 
  #  ssl_prefer_server_ciphers  on; 
 
  #  location / { 
  #  } 
  #} 
 
}
ログイン後にコピー

注: パスはシステム上に存在し、それに対応している必要があります

2. ビルド イメージ コマンドを実行します

コードをコピーしますコードは次のとおりです。次のように:


[root@localhost nginx]# sudo docker build --rm --tag os7/nginx:centos7 .

実行結果のスクリーンショット:

CentOS7 Docker Nginx部署及运行实例分析

3. イメージがインストールされ、正常にビルドされたかどうかを確認します docker イメージ

CentOS7 Docker Nginx部署及运行实例分析

#4. コンテナー docker run を作成します - i -t -d -p 192.168.32.129:81:80 os7/nginx / bin/bash

注: IP アドレスが 192.168.32.129 の場合は、
## を追加する必要があります。

#192.168.32.129 localhost


# in /etc/hosts ##5. コンテナーが正常に作成されたかどうかを確認し、docker ps

CentOS7 Docker Nginx部署及运行实例分析 を起動します6.curl http://192.168.32.129:81

に正常にアクセスできるかどうかをテストします。

CentOS7 Docker Nginx部署及运行实例分析「この接続は拒否されました」と表示されます。解決方法がありますので、まずはコンテナに入りましょう

7. コンテナに入ります docker exec -i -t small_hodgkin /bin/sh

CentOS7 Docker Nginx部署及运行实例分析 #8. 次にコンテナ内で実行します (直接入力するだけです)


nginx


9.curl http://192.168.32.129:81

# を実行します# コンテナの外

#成功しました。 CentOS7 Docker Nginx部署及运行实例分析

10. 仮想マシンの外に出てブラウザ経由でアクセスします

以上がCentOS7 Docker Nginx の導入と実行例の分析の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホット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衣類リムーバー

Video Face Swap

Video Face Swap

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

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

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

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

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

Dockerの画像を更新する方法 Dockerの画像を更新する方法 Apr 15, 2025 pm 12:03 PM

Docker画像を更新する手順は次のとおりです。最新の画像タグ新しい画像をプルする新しい画像は、特定のタグのために古い画像を削除します(オプション)コンテナを再起動します(必要に応じて)

Dockerによってコンテナを出る方法 Dockerによってコンテナを出る方法 Apr 15, 2025 pm 12:15 PM

Dockerコンテナを終了する4つの方法:コンテナ端子でCtrl Dを使用するコンテナターミナルに出口コマンドを入力しますDocker stop&lt; container_name&gt;コマンドを使用するDocker Kill&lt; container_name&gt;ホストターミナルのコマンド(フォース出口)

Dockerのファイルを外部にコピーする方法 Dockerのファイルを外部にコピーする方法 Apr 15, 2025 pm 12:12 PM

Dockerの外部ホストにファイルをコピーする方法:Docker CPコマンドを使用:Docker CP [Options]&lt; Container Path&gt; &lt;ホストパス&gt;。データボリュームの使用:ホストにディレクトリを作成し、-vパラメーターを使用してコンテナを作成するときにディレクトリをコンテナにマウントして、双方向ファイルの同期を実現します。

Dockerを再起動する方法 Dockerを再起動する方法 Apr 15, 2025 pm 12:06 PM

Dockerコンテナを再起動する方法:コンテナID(Docker PS)を取得します。コンテナを停止します(docker stop&lt; container_id&gt;);コンテナを起動します(docker start&lt; container_id&gt;);再起動が成功していることを確認します(Docker PS)。その他の方法:Docker Compose(Docker-Compose Restart)またはDocker API(Dockerドキュメントを参照)。

Dockerデスクトップの使用方法 Dockerデスクトップの使用方法 Apr 15, 2025 am 11:45 AM

Dockerデスクトップの使用方法は? Dockerデスクトップは、ローカルマシンでDockerコンテナを実行するためのツールです。使用する手順には次のものがあります。1。Dockerデスクトップをインストールします。 2。Dockerデスクトップを開始します。 3。Docker Imageを作成します(DockerFileを使用); 4. Docker画像をビルド(Docker Buildを使用); 5。Dockerコンテナを実行します(Docker Runを使用)。

Dockerプロセスを表示する方法 Dockerプロセスを表示する方法 Apr 15, 2025 am 11:48 AM

Dockerプロセス表示方法:1。DockerCLIコマンド:Docker PS; 2。SystemDCLIコマンド:SystemCTL Status Docker; 3。CLIコマンドを作成するDocker:Docker-Compose PS。 4。プロセスエクスプローラー(Windows); 5。 /procディレクトリ(Linux)。

Dockerコンテナの名前を確認する方法 Dockerコンテナの名前を確認する方法 Apr 15, 2025 pm 12:21 PM

すべてのコンテナ(Docker PS)をリストする手順に従って、Dockerコンテナ名を照会できます。コンテナリストをフィルタリングします(GREPコマンドを使用)。コンテナ名(「名前」列にあります)を取得します。

Docker画像が失敗した場合はどうすればよいですか Docker画像が失敗した場合はどうすればよいですか Apr 15, 2025 am 11:21 AM

障害のあるDocker画像ビルドのトラブルシューティング手順:DockerFileの構文と依存関係バージョンを確認します。ビルドコンテキストに必要なソースコードと依存関係が含まれているかどうかを確認します。エラーの詳細については、ビルドログを表示します。 -targetオプションを使用して、階層フェーズを構築して障害点を識別します。 Dockerエンジンの最新バージョンを使用してください。 -t [image-name]:デバッグモードで画像を作成して、問題をデバッグします。ディスクスペースを確認し、十分であることを確認してください。 Selinuxを無効にして、ビルドプロセスへの干渉を防ぎます。コミュニティプラットフォームに助けを求め、DockerFilesを提供し、より具体的な提案のためにログの説明を作成します。

See all articles