"engine-ex"로 발음되는 Nginx는 오픈 소스 웹 서버로, 웹 서버로서의 초기 성공 이후 지금은 역방향 프록시 , HTTP 캐시 및 로드 밸런서로도 사용됩니다.
Nginx를 사용하는 유명 회사로는 Autodesk, Atlassian, Intuit, T-Mobile, GitLab, DuckDuckGo, Microsoft, IBM, Google, Adobe, Salesforce, VMWare, Xerox, LinkedIn, Cisco, Facebook, Target, Citrix Systems, Twitter, Apple이 있습니다. , Intel,출처.
Nginx는 원래 Igor Sysoev에 의해 만들어졌으며 2004년 10월에 첫 공개 릴리스가 되었습니다. Igor는 처음에 10,000개의 동시 연결을 처리하는 성능 문제와 관련된 문제인 C10k 문제 에 대한 해결책으로 소프트웨어를 생각했습니다.
Nginx는 낮은 메모리 사용량 과 높은 동시성을 제공하도록 구축되었습니다. 각 웹 요청에 대해 새 프로세스를 생성하는 대신 Nginx는 요청이 단일 스레드에서 처리되는 비동기식 이벤트 중심 접근 방식을 사용합니다.
Nginx를 사용하면 하나의 마스터 프로세스가 여러 워커 프로세스를 제어할 수 있습니다. 마스터는 워커 프로세스를 유지 관리하고 워커는 실제 처리를 수행합니다. Nginx는 비동기식이므로 다른 요청을 차단하지 않고 워커가 각 요청을 동시에 실행할 수 있습니다.
아래 그래프에서 nginx 사용률이 전반적으로 1등을 하고 있는 모습을 볼 수 있습니다.
구글 트랜드를 통해 사람들의 관심사를 살펴보면 Apache가 확연히 감소하고 있다는 점이 보입니다.
대부분의 웹사이트에서 serverHTTP 헤더를 확인하여 Nginx 또는 Apache인지 확인할 수 있습니다. Chrome Devtools에서 네트워크 탭을 실행하여 HTTP 헤더를 볼 수 있습니다. 또는 Pingdom 또는 GTmetrix 와 같은 도구에서 헤더를 확인할 수 있습니다 .
그러나 HTTP 헤더가 항상 기본 웹 서버를 표시하는 것은 아닙니다. 예를 들어 WordPress 사이트가 Cloudflare와 같은 프록시 서비스 뒤에 있는 경우 serverHTTP 헤더는 대신 cloudflare라고 표시됩니다.
docker pull nginx
docker run -it --rm -d -p 8000:80 --name website nginx
docker stop website
# 첫 째, 컨테이너 내부에서 명령어 실행 nginx -v # 둘 째, 컨테이너 외부! 호스트에서 명령어 실행 docker top website # 셋 째, curl 클라이언트 툴 이용 curl localhost:8000 # 넷 째, 크롬및 사파리 브라우저에 접속 localhost:8000를 주소창에 입력하여 접속한다.
service
는 wrapper script입니다.
여기서 scriptsms systemd service의 start, stop, status와 관련된 일들을 할 수 있도록 해줍니다.
내부적으로 service
script가 initctl
또는 systemctl 또는
/etc/init.d를 사용합니다. 복잡한 일을 할때는 직접
systemctl`등을 이용하지만 start, stop, status 관련 작업은 service script가 더 낫다고 합니다.
예) socket과 관련된 systemd service인 경우 먼저 socket을 stop해줍니다.
참고 - https://askubuntu.com/questions/903354/difference-between-systemctl-and-service-commands
nginx사용을 위한 헬프 명령어입니다.
root@a0cb11fd9540:/# nginx -h
nginx version: nginx/1.21.6
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
[-e filename] [-c filename] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /etc/nginx/)
-e filename : set error log file (default: /var/log/nginx/error.log)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file
FROM nginx
COPY ./html/index.html /usr/share/nginx/index.html
version: "3.8"
services:
nginx:
build:
context: .
dockerfile: ./Dockerfile
image: nginx_mastery_image
container_name: nginx_container
ports:
- 8000:80
volumes:
- ./html/:/usr/share/nginx/html
.
├── Dockerfile
├── README.md
├── docker-compose.yml
└── html
└── index.html
$ docker-compose up -d
$ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------
nginx_container /docker-entrypoint.sh ngin ... Up 0.0.0.0:8000->80/tcp
$ ddocker-compose images
Container Repository Tag Image Id Size
------------------------------------------------------------------------
nginx_container nginx_mastery_image latest 989b7fd874be 134.5 MB