検索
ホームページ運用・保守NginxCentOS7 Docker Nginx をデプロイして実行する方法

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 までご連絡ください。
docker中rm和rmi有什么区别docker中rm和rmi有什么区别Jul 14, 2022 am 11:02 AM

docker中rm和rmi的区别:rm命令用于删除一个或者多个容器,而rmi命令用于删除一个或者多个镜像;rm命令的语法为“docker rm [OPTIONS] CONTAINER [CONTAINER...]”,rmi命令的语法为“docker rmi [OPTIONS] IMAGE [IMAGE...]”。

docker官方镜像有哪些docker官方镜像有哪些May 12, 2022 pm 02:23 PM

docker官方镜像有:1、nginx,一个高性能的HTTP和反向代理服务;2、alpine,一个面向安全应用的轻量级Linux发行版;3、busybox,一个集成了三百多个常用Linux命令和工具的软件;4、ubuntu;5、PHP等等。

docker容器重启后数据会丢吗docker容器重启后数据会丢吗Jun 17, 2022 am 10:41 AM

docker容器重启后数据会丢失的;但是可以利用volume或者“data container”来实现数据持久化,在容器关闭之后可以利用“-v”或者“–volumes-from”重新使用以前的数据,docker也可挂载宿主机磁盘目录,用来永久存储数据。

docker是免费的吗docker是免费的吗Jul 08, 2022 am 11:21 AM

docker对于小型企业、个人、教育和非商业开源项目来说是免费的;2021年8月31日,docker宣布“Docker Desktop”将转变“Docker Personal”,将只免费提供给小型企业、个人、教育和非商业开源项目使用,对于其他用例则需要付费订阅。

docker能安装oracle吗docker能安装oracle吗Jul 08, 2022 pm 04:07 PM

docker能安装oracle。安装方法:1、拉取Oracle官方镜像,可以利用“docker images”查看镜像;2、启动容器后利用“docker exec -it oracle11g bash”进入容器,并且编辑环境变量;3、利用“sqlplus /nolog”进入oracle命令行即可。

docker存储空间不足怎么办docker存储空间不足怎么办Jul 22, 2022 pm 03:44 PM

解决方法:1、停止docker服务后,利用“rsync -avz /var/lib/docker 大磁盘目录/docker/lib/”将docker迁移到大容量磁盘中;2、编辑“/etc/docker/daemon.json”添加指定参数,将docker的目录迁移绑定;3、重载和重启docker服务即可。

有类似docker的软件吗有类似docker的软件吗May 12, 2022 pm 03:39 PM

有类似docker的软件:1、Podman,是一个无守护程序的开源Linux原生容器引擎;2、LXD,是一个专为LXC Linux容器设计的开源容器引擎;3、Buildah,是是红帽为容器化系统开发的一个OCI镜像构建工具;4、RunC等。

docker容器管理ui有哪些docker容器管理ui有哪些May 11, 2022 pm 03:39 PM

容器管理ui工具有:1、Portainer,是一个轻量级的基于Web的Docker管理GUI;2、Kitematic,是一个GUI工具,可以更快速、更简单的运行容器;3、LazyDocker,基于终端的一个可视化查询工具;4、DockStation,一款桌面应用程序;5、Docker Desktop,能为Docker设置资源限制,比如内存,CPU,磁盘镜像大小;6、Docui。

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ヘンタイを無料で生成します。

ホットツール

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

AtomエディタMac版ダウンロード

AtomエディタMac版ダウンロード

最も人気のあるオープンソースエディター

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

SecLists

SecLists

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