> 운영 및 유지보수 > 엔진스 > CentOS7 Docker Nginx를 배포하고 실행하는 방법

CentOS7 Docker Nginx를 배포하고 실행하는 방법

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
풀어 주다: 2023-05-20 15:19:06
앞으로
989명이 탐색했습니다.

1. 리소스 준비

dockerfile 파일

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

# "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 파일

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

# 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 이미지가 성공적으로 설치되고 빌드되었는지 확인하세요. bin/bash

CentOS7 Docker Nginx如何部署及运行참고: IP가 192.168.32.129 인 경우 /etc/hosts localhost


5에


192.168.32.129를 추가해야 합니다. 컨테이너가 성공적으로 생성되었는지 확인하고 docker ps

를 시작합니다.

6. 컬 http://192.168.32.129에 성공적으로 접속했는지 테스트하세요:81

CentOS7 Docker Nginx如何部署及运行

이 연결이 거부되었습니다. 어떻게 해야 하나요? 해결 방법이 있으니 먼저 컨테이너에 들어가 보겠습니다

7. 컨테이너에 docker exec -i -t small_hodgkin /bin/shCentOS7 Docker Nginx如何部署及运行

8을 입력합니다.

CentOS7 Docker Nginx如何部署及运行nginx


9. 컨테이너 외부에서 컬 http://192.168.32.129:81 실행이 성공했습니다.

10. 가상머신 외부의 브라우저를 통해 접속하세요

위 내용은 CentOS7 Docker Nginx를 배포하고 실행하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿