>  기사  >  운영 및 유지보수  >  Nginx 서비스를 배포하는 방법

Nginx 서비스를 배포하는 방법

王林
王林앞으로
2023-05-12 10:13:171463검색

1. Nginx 소개:

1.1 Nginx란 무엇인가요?

Nginx("engine x")는 고성능, 동시성 www 서비스 및 프록시 서비스를 지원하는 오픈 소스 소프트웨어입니다.

러시아 Igor Sysoev가 개발한 이 앱은 원래 러시아의 대형 웹사이트 www.rambler.ru에서 사용되었습니다.

Nginx는 높은 동시성과 낮은 시스템 리소스 사용량을 특징으로 합니다.

Nginx는 UNIX, Linux, DSB, Mac OS X, Solaris 및 Windows 운영 체제에서 실행될 수 있습니다.

1.2 Nginx 주요 기능

높은 동시성 지원: 수만 개의 동시 연결 지원 가능

낮은 리소스 소비: 동시 연결 30,000개 미만, 처음 10개 스레드는 200MB 미만의 메모리를 소비합니다.

HTTP 역방향 프록시 및 가속 캐싱, 즉 로드 밸런싱 기능, RS 노드 서버에 대한 상태 확인 기능 내장

Squid 등 전문 캐싱 소프트웨어의 캐싱 기능 포함

비동기 네트워크 I/O 이벤트 지원 model

1.3 Nginx 소프트웨어의 주요 기능 응용

웹 서비스 소프트웨어

역방향 프록시 및 로드 밸런싱 서비스

프런트엔드 비즈니스 데이터 캐싱 서비스

2.Nginx 웹 서비스

2.1 웹으로서의 Nginx 서버 응용 시나리오

Nginx를 사용하여 HTML, JS, CSS, 작은 그림 등과 같은 정적 데이터를 실행합니다.

Nginx는 FastCGI와 결합하여 PHP와 같은 동적 프로그램을 실행합니다.

Nginx는 Tomcat/Resin 등을 결합하여 Java를 지원합니다. 동적 프로그램

2.2 웹 서버 선택 방법

작업 중 필요에 따라 적합한 비즈니스를 선택하세요. 서비스 소프트웨어:

  • 정적 비즈니스: 동시성이 높은 시나리오에서는 Nginx가 선호됩니다. Nginx를 설치하는 방법에는 여러 가지가 있습니다

  • . 이 기사에서는 컴파일 및 설치 방법을 사용합니다. 대규모 배포가 필요한 경우 비즈니스 요구 사항에 따라 rpm 패키지를 사용자 정의한 후 Ansible을 통해 설치할 수 있습니다.
  • 3.1 pcre 라이브러리 설치

  • 현재 시스템 버전 보기:
  • cat /etc/redhat-release
    uname -r

    결과:

    CentOS release 6.10 (Final)
    2.6.32-754.el6.x86_64
  • yum 방법을 사용하여 pcre 설치:
yum -y install pcre pcre-devel
rpm -qa pcre pcre-devel

결과:

pcre-devel-7.8-7.el6.x86_64

pcre -7.8 -7.el6.x86_64

3.2 Nginx 설치

openssl과 openssl-devel이 설치되어 있는지 확인하세요.

rpm -qa openssl openssl-devel

결과: 그렇지 않은 경우 yum을 사용하여 설치하세요

openssl-1.0.1e-57.el6.x86_64
openssl-devel-1.0.1e-57.el6.x86_64

nginx 패키지 저장 디렉터리 만들기:
mkdir -p /app/nginx-1.8.1
mkdir -p /server/tools
cd /server/tools/

nginx 소프트웨어 다운로드 패키지:

공식 주소: www.nginx.rog
wget -q http://nginx.org/download/nginx-1.8.1.tar.gz

nginx 사용자 생성:

useradd nginx -s /sbin/nologin -M

소프트웨어 패키지의 압축을 풀고 압축이 풀린 디렉터리로 들어갑니다:

tar xf nginx-1.8.1.tar.gz
cd nginx-1.8.1

컴파일:

컴파일된 모듈은 ./를 통해 볼 수 있습니다. 구성 --help

./configure --user=nginx --group=nginx --prefix=/app/nginx-1.8.1/ --with-http_stub_status_module --with-http_ssl_module

설치:

make
make install

소프트 링크 생성: 사용 및 버전 업그레이드에 편리함

ln -s /app/nginx-1.8.1/ /app/nginx

사전 시작 테스트:

/app/nginx/sbin/nginx -t

결과:

nginx: 구성 파일 /app/nginx-1.8. 1//conf/nginx .conf 구문은 oknginx입니다: 구성 파일 /app/nginx-1.8.1//conf/nginx.conf 테스트가 성공했습니다

Nginx 서비스를 시작하고 포트를 확인하세요:

/app/nginx/sbin/nginx
netstat -utpln | grep 80

결과:

tcp 0 0 0.0.0.0 ;

결과:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h2>Welcome to nginx!</h2>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/" rel="external nofollow" >nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/" rel="external nofollow" >nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

4. Nginx 디렉터리 구조 및 구성 파일

4.1 Nginx 디렉터리 구조 설명

tree /app/nginx
/app/nginx
├── client_body_temp
├── conf							#nginx配置文件目录
│   ├── fastcgi.conf				#fastcgi相关参数配置文件
│   ├── fastcgi.conf.default
│   ├── fastcgi_params				#fastcgi参数文件
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types					#媒体类型
│   ├── mime.types.default
│   ├── nginx.conf					#Nginx主配置文件
│   ├── nginx.conf.default
│   ├── scgi_params					#scgi配置文件
│   ├── scgi_params.default
│   ├── uwsgi_params				#uwsgi配置文件
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp					#fastcgi临时数据文件
├── html							#默认站点目录
│   ├── 50x.html					#错误页面显示文件
│   └── index.html					#默认的站点首页文件
├── logs							#默认日志路径
│   ├── access.log					#默认访问日志文件
│   ├── error.log					#默认错误日志文件
│   └── nginx.pid					#Nginx的pid文件
├── proxy_temp						#临时目录
├── sbin							#Nginx命令目录
│   ├── nginx						#启动命令
│   └── nginx.old
├── scgi_temp						#临时目录
└── uwsgi_temp						#临时目录

9 directories, 22 files

4.2 Nginx 기본 구성 파일

구성 파일을 표시하려면 댓글로 이동하세요.
egrep -v "#|^$" /app/nginx/conf/nginx.conf.default

결과:

worker_processes  1;                            #worker进程数量
events {                                        #事件区块开始
    worker_connections  1024;                    #单worker进程支持的最大连接
}                                                #事件区块结束
http {                                            #HTTP区块开始
    include       mime.types;                    #支持的媒体类型库
    default_type  application/octet-stream;        #默认媒体类型
    sendfile        on;                            #开启高效传输模式
    keepalive_timeout  65;                        #连接超时
    server {                                    #server区块开始
        listen       80;                        #服务端口,默认80
        server_name  localhost;                    #域名主机名
        location / {                            #location区块开始
            root   html;                        #站点根目录
            index  index.html index.htm;        #默认首页文件
        }                                        #location区块结束
        error_page   500 502 503 504  /50x.html;#对应状态码及回应
        location = /50x.html {                    #location开始回应50x.html
            root   html;                        #站点目录为html
        }                                        
    }
}                                                #HTTP区块结束
참고: 서버 블록과 위치 블록이 여러 개 있을 수 있습니다.

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

성명:
이 기사는 yisu.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제