Docker가 nginx를 배포하고 구성 파일을 수정하는 방법

WBOY
풀어 주다: 2023-05-12 15:19:13
앞으로
1427명이 탐색했습니다.

명령어 한 줄이면 가능합니다:

docker run \
 --name nginx-health-web-pc \
 -d -p 6800:80 \
 -v /usr/docker/nginx/html:/usr/share/nginx/html \
 nginx
로그인 후 복사

달리고 시작하는 것이 즐겁습니다~~~~~ 이때 갑자기 프론트엔드가 와서 "nginx에 구성을 추가해야 합니다"라고 했습니다. , 그리고 그 분이 말씀해주셨는데, "누구누구는 예전에 이런 '맞추기'를 했었는데,

물론 이때 경쟁력이 있다면 거절할 수는 없지만 그래도 노력이 좀 필요해요. 일반적인 상황에서는 docker가 시작될 때 구성됩니다. 간단하고 편리합니다. 그러나 nginx는 먼저 기본 구성 파일 nginx.conf를 로드합니다. nginx.conf의 conf.d 디렉터리에 있는 파일(일반적으로 하나 이상의 default.conf 파일) 이는 디렉토리만 마운트하는 것보다 훨씬 번거롭지만 명확한 아이디어가 있는 한 어렵지 않습니다.

마운트된 명령을 먼저 살펴보겠습니다.

Docker 시작 명령

docker run \
 --name mynginx \
 -d -p 80:80 \
 -v /usr/docker/mynginx/html:/usr/share/nginx/html \
 -v /etc/docker/mynginx/nginx.conf:/etc/nginx/nginx.conf:ro \
 -v /etc/docker/mynginx/conf.d:/etc/nginx/conf.d \
 nginx
로그인 후 복사

여기서 주의할 점이 몇 가지 있습니다.

(1) 첫 번째 "-v"는 프로젝트 위치입니다. 마운트된 디렉토리로 이동하세요.

(2) 두 번째 "-v"는 마운트된 기본 구성 파일 "nginx.conf"에 "nginx.conf" 줄이 있습니다. "file /nginx/conf.d/*.conf;", 이 포함은 하위 구성 파일의 경로를 가리킵니다. 포함 뒤의 경로는 틀리지 않아야 합니다.

(3) 세 번째 "-v"는 또한 docker의 하위 구성 파일 경로를 마운트합니다.

(4) nginx를 강조하는 것이 중요합니다. conf is 파일이 마운트되고(docker는 이런 식으로 사용하지 않는 것이 좋습니다), conf.d가 디렉토리를 마운트합니다. 먼저 시작해보면 아직 구성 파일이 없기 때문에 문제가 있음을 알 수 있습니다.

구성 파일 구성

기존 방법으로 nginx를 설치할 때 생성되는 구성 파일(보통 "/etc/nginx" 아래)을 찾아 위의 시작 명령에서 마운트 위치에 해당하는 기본 구성을 넣어줍니다. nginx.conf 파일을 해당 위치 "/etc/docker/mynginx/nginx.conf"에 넣고, 하위 구성 파일 "default.conf"를 "/etc/docker/mynginx/conf.d" 디렉터리에 넣습니다.

시작 명령을 다시 실행하세요.

이제 docker의 파일을 마음대로 구성할 수 있습니다. 이는 기본 설치와 정확히 동일합니다. 마운트된 파일은 실행 시 docker 프로세스에 로드되어야 합니다. 이렇게 하면 혼란이 줄어듭니다. -------------------------------------- ---구분선------------------------------- --- ----------

내 구성 파일 게시:

nginx.conf

user root;
worker_processes 1;
 
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;
 
 autoindex on;
 
 #gzip on;
 
 include /etc/nginx/conf.d/*.conf;
 client_max_body_size 100m;
 client_header_buffer_size 128k;
 large_client_header_buffers 4 128k;
}
로그인 후 복사

default.conf

server {
 listen  80;
 server_name localhost;
 
 #charset koi8-r;
 #access_log /var/log/nginx/log/host.access.log main;
 
 location / {
  root /usr/nginx/dacheng-wechat-web;
  # root /usr/nginx/html;
  index index.html index.htm;
  autoindex on;
 try_files $uri /index/index/page.html;
  #try_files $uri /index/map/page.html;
 }
 
 #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 /usr/share/nginx/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's document root
 # concurs with nginx's one
 #
 #location ~ /\.ht {
 # deny all;
 #}
}
로그인 후 복사

위 내용은 Docker가 nginx를 배포하고 구성 파일을 수정하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:yisu.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!