docker 의 nginx 용기 배치 에 접근 하기
docker search nginx  2 nginx 미 러
docker pull nginx  3. 용 기 를 만 들 고 포트 맵, 디 렉 터 리 맵 을 설정 합 니 다.
#  /root     nginx      nginx    
mkdir ~/nginx
cd ~/nginx
mkdir conf
cd conf
#  ~/nginx/conf/   nginx.conf  ,      
vim nginx.conf  user  nginx;
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;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}
  docker run -id --name=c_nginx \
-p 80:80 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx  매개 변수 설명:
-p 80: 80: 용기 의 80 포트 를 호스트 의 80 포트 에 표시 합 니 다.용 기 는 작은 Liux 에 해당 합 니 다. 외부 네트워크 가 용기 에 접근 하려 는 절차 입 니 다. 먼저 아 리 클 라 우 드 의 안전 그룹 (아 리 클 라 우 드 서버 를 사용한다 면) 을 방문 하여 80 포트 를 놓 았 는 지 확인 한 다음 에 Liux 의 방화벽 을 방문 하여 80 을 놓 았 는 지 확인 한 다음 에 my sql 용 기 를 방문 하여 80 을 놓 았 는 지 확인 합 니 다.그래서 여기 서 비 춰 야 합 니 다. 비 추 는 것 은 바로 그것 을 폭로 하 는 것 입 니 다. 아래 의 nginx 같은 것 은 다 똑 같 습 니 다. 더 이상 말 하지 않 겠 습 니 다.
-v $PWD / conf / nginx. conf: / etc / nginx / nginx. conf: 호스트 의 현재 디 렉 터 리 에 있 는 / conf / nginx. conf 를 용기 에 마 운 트 하 는: / etc / nginx / nginx. conf.디 렉 터 리 설정
- v $PWD / logs: / var / log / nginx: 호스트 의 현재 디 렉 터 리 에 있 는 logs 디 렉 터 리 를 용기 에 마 운 트 하 는 / var / log / nginx.로그 디 렉 터 리.
2. 역방향 대리 작업 을 한다.
docker ps  nginx 용기 의 id 번 호 를 조회 한 결 과 는 다음 과 같 습 니 다.
CONTAINER ID   IMAGE       COMMAND                  CREATED       STATUS       PORTS                                       NAMES
3929aa630523   nginx       "/docker-entrypoint.…"   2 hours ago   Up 2 hours   0.0.0.0:80->80/tcp, :::80->80/tcp           c_nginx
cf152c11389b   redis       "docker-entrypoint.s…"   2 weeks ago   Up 2 weeks   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   c_redis
e24660ccf0b8   mysql:5.6   "docker-entrypoint.s…"   2 weeks ago   Up 2 weeks   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp   c_mysql
  nginx 의 Id 를 복사 합 니 다.
docker exec -it 3929aa630523 bash  대화 식 으로 용기 에 들어가다.
root@3929aa630523:/# which nginx
/usr/sbin/nginx
  nginx 위 치 를 찾 습 니 다. - v $PWD / conf / nginx. conf: / etc / nginx / nginx. conf \ / etc / nginx / conf 에 마 운 트 되 었 기 때 문 입 니 다.
cd /etc/nginx/
root@3929aa630523:/etc/nginx# ls
conf.d		koi-utf  mime.types  nginx.conf   uwsgi_params
fastcgi_params	koi-win  modules     scgi_params  win-utf
root@3929aa630523:/etc/nginx# cat nginx.conf 
user  nginx;
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;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}
  include /etc/nginx/conf.d/*.conf;이 주소 에 키 프로필 을 설정 한 것 입 니 다.
root@3929aa630523:/etc/nginx# cd conf.d/
root@3929aa630523:/etc/nginx/conf.d# ls
default.conf
root@3929aa630523:/etc/nginx/conf.d# cat default.conf 
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    #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;
    #}
}
  여기 서 고치 면 돼.
하지만 vim 을 사용 하려 고 할 때 나타 납 니 다.
root@3929aa630523:/etc/nginx/conf.d# vim default.conf 
bash: vim: command not found
  이 럴 때 는 vim 를 설치 해 야 합 니 다.
그러나 apt - get install vim 명령 을 두 드 렸 을 때 알림:
Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package vim
이 때 두 드 려 야 합 니 다: apt - get update. 이 명령 의 역할 은 동기 화 / etc / apt / sources. list 와 / etc / apt / sources. list. d 에 열 거 된 원본 색인 입 니 다. 그래 야 최신 패 키 지 를 얻 을 수 있 습 니 다.
root@3929aa630523:/etc/nginx/conf.d# apt-get update
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:2 http://deb.debian.org/debian buster InRelease [121 kB]
Get:3 http://security.debian.org/debian-security buster/updates/main amd64 Packages [285 kB]
Get:4 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7907 kB]
Get:6 http://deb.debian.org/debian buster-updates/main amd64 Packages [10.9 kB]                       
Fetched 8441 kB in 4min 51s (29.0 kB/s)                                                               
Reading package lists... Done
  업데이트 가 끝 난 후에 명령 을 누 르 십시오: apt - get install vim 명령 을 누 르 면 됩 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단! Certbot을 사용하여 웹 사이트를 SSL(HTTPS)화하는 방법초보자가 인프라 주위를 정돈하는 것은 매우 어렵습니다. 이번은 사이트를 간단하게 SSL화(HTTP에서 HTTPS통신)로 변경하는 방법을 소개합니다! 이번에는 소프트웨어 시스템 Nginx CentOS7 의 환경에서 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.