백엔드 개발 PHP 튜토리얼 Linux에서 nginx 설치 및 구성에 대한 자세한 설명

Linux에서 nginx 설치 및 구성에 대한 자세한 설명

Feb 07, 2017 pm 04:52 PM

1. Linux에서 nginx 설치 및 구성

nginx를 처음 설치하는 과정에서 발생하는 문제는 단계별로 해결됩니다.

서버에 연결하고 로그인하는 데 사용되는 도구는 secureCRT입니다.

1.1 rz 명령을 실행하면 대화 상자가 나타나면 업로드할 nginx 압축 패키지를 선택하세요.

#rz
로그인 후 복사

1.2 압축 풀기

[root@vw010001135067 ~]# cd /usr/local/
[root@vw010001135067 local]# tar -zvxf nginx-1.10.2.tar.gz
로그인 후 복사

1.3 nginx 폴더에 들어가서 ./configure 명령을 실행합니다

[root@vw010001135067 local]# cd nginx-1.10.2
[root@vw010001135067 nginx-1.10.2]# ./configure
로그인 후 복사

다음과 같이 오류가 보고됩니다.

checking for OS
 + Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... not found
 
./configure: error: C compiler cc is not found
로그인 후 복사

이 오류가 발생합니다. 그러면 gcc 패키지가 설치되지 않습니다.

1.3.1 gcc 설치

gcc 보기

[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc:
로그인 후 복사

gcc 설치

[root@vw010001135067 nginx-1.10.2]# yum -y install gcc
로그인 후 복사

설치 성공 후 다시 확인해 보세요

[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
로그인 후 복사

gcc가 설치되어 있습니다.

1.3.2 계속 실행하여 ./configure

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for OS
 + Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
......
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
 
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
로그인 후 복사

위 오류가 발생합니다. pcre-devel

[root@vw010001135067 nginx-1.10.2]# yum install pcre-devel
로그인 후 복사

1.3.3을 설치하고 다시 실행하세요./configure

error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
로그인 후 복사

이 오류가 발생하면

yum install zlib-devel
로그인 후 복사
를 실행하세요.

1.3.4 ./configure

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for OS
 + Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
.......
Configuration summary
 + using system PCRE library
 + OpenSSL library is not used
 + md5: using system crypto library
 + sha1: using system crypto library
 + using system zlib library
 
 nginx path prefix: "/usr/local/nginx"
 nginx binary file: "/usr/local/nginx/sbin/nginx"
 nginx modules path: "/usr/local/nginx/modules"
 nginx configuration prefix: "/usr/local/nginx/conf"
 nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
 nginx pid file: "/usr/local/nginx/logs/nginx.pid"
 nginx error log file: "/usr/local/nginx/logs/error.log"
 nginx http access log file: "/usr/local/nginx/logs/access.log"
 nginx http client request body temporary files: "client_body_temp"
 nginx http proxy temporary files: "proxy_temp"
 nginx http fastcgi temporary files: "fastcgi_temp"
 nginx http uwsgi temporary files: "uwsgi_temp"
 nginx http scgi temporary files: "scgi_temp"
로그인 후 복사

1.4 openssl 기능을 사용하려면 sha1 기능을 실행한 후 오류가 보고되지 않습니다. 그런 다음 openssl을 설치하고 sha1

[root@vw010001135067 nginx-1.10.2]# yum install openssl openssl-devel
[root@vw010001135067 nginx-1.10.2]# install perl-Digest-SHA1.x86_64
로그인 후 복사

1.4.1 SSL 모듈 실행을 활성화합니다./configure –with-http_ssl_module

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_ssl_module
로그인 후 복사

1.4.2 활성화 " server+status" 페이지에서 ./configure –with-http_stub_status_module

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module
로그인 후 복사

위의 두 명령을 동시에 시작할 수 있습니다

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module --with-http_ssl_module
로그인 후 복사

1.5 위의 구성에는 통과

make 명령어 실행, make install 명령어 실행

[root@vw010001135067 nginx-1.10.2]# make
[root@vw010001135067 nginx-1.10.2]# make install
로그인 후 복사

이때 nginx 실행 성공

1.6 환경변수 설정

/etc /profile에서 구성 추가

구성 파일 열기

[root@vw010001135067 nginx-1.10.2]# vi /etc/profile
로그인 후 복사

구성 파일에

#nginx configure
export NGINX_HOME=/usr/local/nginx-1.10.2
export PATH=$PATH:$NGINX_HOME/sbin
로그인 후 복사

추가

위와 같이 채우기 시작했는데, nginx -v를 사용해도 찾을 수 없었습니다. 위의 nginx_home 구성 주소가 잘못되었음을 확인했습니다. 먼저 nginx

[root@vw010001135067 nginx-1.10.2]# whereis nginx
nginx: /usr/local/nginx
로그인 후 복사

설치 주소를 찾아보세요. 주소가 정말 틀리네요. 위의 내용을

#nginx configure
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
로그인 후 복사

로 변경하세요. 🎜>

컴파일 후 저장하고 종료한 후

[root@vw010001135067 nginx-1.10.2]# source /etc/profile
로그인 후 복사


를 실행하여 구성을 적용합니다.

1.7 nginx 버전 보기

[root@vw010001135067 nginx]# nginx -v
nginx version: nginx/1.10.2
로그인 후 복사

전체 과정이 성공적으로 완료되었습니다!

2. nginx.conf 수정

2.1 nginx 시작

내 nginx 서비스는 http://10.1.135.67/에 있습니다. 이제 nginx를 시작하세요.

[root@vw010001135067 nginx]# cd /usr/local/nginx
[root@vw010001135067 nginx]# nginx -c conf/nginx.conf
로그인 후 복사

성공적으로 시작되었습니다. 브라우저에서 http://10.1.135.67/을 엽니다. 기본 포트 번호는 80입니다.

Linux에서 nginx 설치 및 구성에 대한 자세한 설명

위와 같이 nginx는 이미 정상적으로 작동하고 있습니다.

2.2 Tomcat 서비스 구성

이제 내 Tomcat 서비스는 10.1.29.15에 있으며 nginx를 통해 전달되어야 합니다. 그런 다음 nginx.conf를 열고 구성 파일을 수정합니다. 다음과 같이 추가하세요:

#user nobody;
worker_processes 1;
 
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
 
#pid  logs/nginx.pid;
 
 
events {
 worker_connections 1024;#最大连接数,默认为512
 accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
 multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
 #use epoll;  #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport 
}
 
 
http {
 #文件扩展名与文件类型映射表
 include  mime.types;
 
 #默认文件类型,默认为text/plain 
 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;; 
 
 #combined为日志格式的默认值
 access_log logs/access.log main;
 
 #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块
 sendfile  on;
 sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。
 
 #tcp_nopush  on;
 
 #连接超时时间,默认为75s,可以在http,server,location块。
 keepalive_timeout 65;
 
 #gzip on;
 
 upstream upload {
  server 10.1.29.15:8080;
 }
 
 error_page 404 https://www.baidu.com; #错误页
 
 server {
  keepalive_requests 120; #单连接请求上限次数。
  listen  80; #监听端口
  server_name localhost; #监听地址 
 
  #charset koi8-r;
 
  #access_log logs/host.access.log main;
 
  location ~ ^.*?/upload/[^/]*?$ {
   proxy_connect_timeout 15;
   proxy_send_timeout 15;
   proxy_read_timeout 15;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header Connection "";
   proxy_pass http://upload; #请求转向upload 定义的服务器列表
   client_max_body_size 1024m;
} 
 }
}
로그인 후 복사

구성 후 구성 파일을 저장하고 nginx를 다시 시작하세요

[root@vw010001135067 nginx]# nginx -s reload
로그인 후 복사

브라우저에서 업로드 프로젝트 호출 성공 여부

Linux에서 nginx 설치 및 구성에 대한 자세한 설명

그림과 같이 프로젝트에 올바르게 접근이 되면서 설정에 성공하게 됩니다!

위 내용은 이 글의 전체 내용입니다. 모든 분들의 학습에 도움이 되기를 바랍니다.

Linux에서 nginx 설치 및 구성에 대한 자세한 내용을 보려면 PHP 중국어 웹사이트를 참고하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

JWT (JSON Web Tokens) 및 PHP API의 사용 사례를 설명하십시오. JWT (JSON Web Tokens) 및 PHP API의 사용 사례를 설명하십시오. Apr 05, 2025 am 12:04 AM

JWT는 주로 신분증 인증 및 정보 교환을 위해 당사자간에 정보를 안전하게 전송하는 데 사용되는 JSON을 기반으로 한 개방형 표준입니다. 1. JWT는 헤더, 페이로드 및 서명의 세 부분으로 구성됩니다. 2. JWT의 작업 원칙에는 세 가지 단계가 포함됩니다. JWT 생성, JWT 확인 및 Parsing Payload. 3. PHP에서 인증에 JWT를 사용하면 JWT를 생성하고 확인할 수 있으며 사용자 역할 및 권한 정보가 고급 사용에 포함될 수 있습니다. 4. 일반적인 오류에는 서명 검증 실패, 토큰 만료 및 대형 페이로드가 포함됩니다. 디버깅 기술에는 디버깅 도구 및 로깅 사용이 포함됩니다. 5. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

확실한 원칙과 PHP 개발에 적용되는 방법을 설명하십시오. 확실한 원칙과 PHP 개발에 적용되는 방법을 설명하십시오. Apr 03, 2025 am 12:04 AM

PHP 개발에서 견고한 원칙의 적용에는 다음이 포함됩니다. 1. 단일 책임 원칙 (SRP) : 각 클래스는 하나의 기능 만 담당합니다. 2. Open and Close Principle (OCP) : 변경은 수정보다는 확장을 통해 달성됩니다. 3. Lisch의 대체 원칙 (LSP) : 서브 클래스는 프로그램 정확도에 영향을 미치지 않고 기본 클래스를 대체 할 수 있습니다. 4. 인터페이스 격리 원리 (ISP) : 의존성 및 사용되지 않은 방법을 피하기 위해 세밀한 인터페이스를 사용하십시오. 5. 의존성 반전 원리 (DIP) : 높고 낮은 수준의 모듈은 추상화에 의존하며 종속성 주입을 통해 구현됩니다.

시스템 재시작 후 UnixSocket의 권한을 자동으로 설정하는 방법은 무엇입니까? 시스템 재시작 후 UnixSocket의 권한을 자동으로 설정하는 방법은 무엇입니까? Mar 31, 2025 pm 11:54 PM

시스템이 다시 시작된 후 UnixSocket의 권한을 자동으로 설정하는 방법. 시스템이 다시 시작될 때마다 UnixSocket의 권한을 수정하려면 다음 명령을 실행해야합니다.

PHP에서 늦은 정적 결합의 개념을 설명하십시오. PHP에서 늦은 정적 결합의 개념을 설명하십시오. Mar 21, 2025 pm 01:33 PM

기사는 PHP 5.3에 도입 된 PHP의 LSB (Late STATIC BING)에 대해 논의하여 정적 방법의 런타임 해상도가보다 유연한 상속을 요구할 수있게한다. LSB의 실제 응용 프로그램 및 잠재적 성능

PHP의 CURL 라이브러리를 사용하여 JSON 데이터가 포함 된 게시물 요청을 보내는 방법은 무엇입니까? PHP의 CURL 라이브러리를 사용하여 JSON 데이터가 포함 된 게시물 요청을 보내는 방법은 무엇입니까? Apr 01, 2025 pm 03:12 PM

PHP 개발에서 PHP의 CURL 라이브러리를 사용하여 JSON 데이터를 보내면 종종 외부 API와 상호 작용해야합니다. 일반적인 방법 중 하나는 컬 라이브러리를 사용하여 게시물을 보내는 것입니다 ...

프레임 워크 보안 기능 : 취약점 보호. 프레임 워크 보안 기능 : 취약점 보호. Mar 28, 2025 pm 05:11 PM

기사는 입력 유효성 검사, 인증 및 정기 업데이트를 포함한 취약점을 방지하기 위해 프레임 워크의 필수 보안 기능을 논의합니다.

프레임 워크 사용자 정의/확장 : 사용자 정의 기능을 추가하는 방법. 프레임 워크 사용자 정의/확장 : 사용자 정의 기능을 추가하는 방법. Mar 28, 2025 pm 05:12 PM

이 기사에서는 프레임 워크에 사용자 정의 기능 추가, 아키텍처 이해, 확장 지점 식별 및 통합 및 디버깅을위한 모범 사례에 중점을 둡니다.

See all articles