Nginx 설치 · 1 min read · Jan 24, 2026

Fedora 12에서 PHP5 및 MySQL 지원으로 Nginx 설치 - 페이지 2

5 nginx 구성

nginx 구성은 /etc/nginx/nginx.conf에 있으며, 지금 열어보겠습니다:

vi /etc/nginx/nginx.conf

구성은 이해하기 쉽습니다 (여기에서 더 배울 수 있습니다: http://wiki.codemongers.com/NginxFullExample 및 여기: http://wiki.codemongers.com/NginxFullExample2)

먼저 (선택 사항) 작업 프로세스 수를 늘리고 keepalive_timeout을 합리적인 값으로 설정할 수 있습니다:

| [...] worker_processes 5; [...] keepalive_timeout 2; [...] |

가상 호스트는 server {} 컨테이너에서 정의됩니다. 기본 vhost를 다음과 같이 수정해 보겠습니다:

| [...] server { listen 80; server_name _; #charset koi8-r; #access_log logs/host.access.log main; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } # 서버 오류 페이지를 정적 페이지 /50x.html로 리디렉션 # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # PHP 스크립트를 127.0.0.1:80에서 수신 대기하는 Apache로 프록시 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # 127.0.0.1:9000에서 수신 대기하는 FastCGI 서버로 PHP 스크립트 전달 # location ~ \.php$ { root html; try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; } # Apache의 문서 루트와 nginx의 문서 루트가 일치할 경우 .htaccess 파일에 대한 접근 거부 # location ~ /\.ht { deny all; } } [...] |

servername ;는 이것을 기본 catchall vhost로 만듭니다 (물론 www.example.com과 같은 호스트 이름을 여기에서 지정할 수도 있습니다).

location / 부분에서 index.php를 인덱스 줄에 추가했습니다. root /usr/share/nginx/html;는 문서 루트가 /usr/share/nginx/html 디렉토리임을 의미합니다.

PHP에 중요한 부분은 location ~ .php$ {} 구문입니다. 활성화하려면 주석을 제거하세요. root 줄을 웹 사이트의 문서 루트로 변경하세요 (예: root /usr/share/nginx/html;). fastcgi_param 줄을 fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;로 변경해야 합니다. 그렇지 않으면 PHP 인터프리터가 브라우저에서 호출하는 PHP 스크립트를 찾지 못합니다.

이제 파일을 저장하고 nginx를 재시작합니다:

/etc/init.d/nginx stop  
/etc/init.d/nginx start

(/etc/init.d/nginx restart를 사용할 수 없었습니다. 왜냐하면 nginx를 중지했지만 시작하지 못했기 때문입니다 - 이유는 모르겠습니다…)

이제 문서 루트 /usr/share/nginx/html에 다음 PHP 파일을 생성합니다…

vi /usr/share/nginx/html/info.php

| |

이제 브라우저에서 해당 파일을 호출합니다 (예: http://192.168.0.100/info.php):

보시다시피, PHP5가 작동하고 있으며, Server API 줄에 표시된 대로 FastCGI를 통해 작동하고 있습니다. 아래로 스크롤하면 MySQL 모듈을 포함하여 PHP5에서 이미 활성화된 모든 모듈을 볼 수 있습니다:

6 링크

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.