"Nginx"의 두 판 사이의 차이

오픈소스 비즈니스 컨설팅
둘러보기로 가기 검색하러 가기
잔글
 
(같은 사용자의 중간 판 24개는 보이지 않습니다)
1번째 줄: 1번째 줄:
 
비동기 이벤트 기반의 Web Server인 nginx를 정리 합니다.
 
비동기 이벤트 기반의 Web Server인 nginx를 정리 합니다.
  
*홈페이지 : http://www.nginx.net/
+
*홈페이지 : http://www.nginx.net/
*다운로드 :  
+
**매뉴얼 : http://nginx.org/en/docs/
*라이선스 :  
+
*다운로드 : http://wiki.nginx.org/Install
*플랫폼 : C
+
*라이선스 :
 +
*플랫폼 : C
  
 
== nginx 개요 ==
 
== nginx 개요 ==
  
 +
== Nginx 설치 ==
  
 
+
=== CentOS 6.5에 nginx 설치 ===
== CentOS 6.5에서 설치 ==
 
  
 
'''<span style="color:#0000FF;"><span style="font-size:larger;">Nginx&nbsp;저장소&nbsp;생성</span></span>'''
 
'''<span style="color:#0000FF;"><span style="font-size:larger;">Nginx&nbsp;저장소&nbsp;생성</span></span>'''
18번째 줄: 19번째 줄:
 
{| cellspacing="1" cellpadding="1" style="width: 100%;"
 
{| cellspacing="1" cellpadding="1" style="width: 100%;"
 
|-
 
|-
| style="background-color: rgb(241, 241, 241);" | [nginx]<br/>name=nginx repo<br/>baseurl=[http://nginx.org/packages/centos/$releasever/$basearch/ http://nginx.org/packages/centos/$releasever/$basearch/]<br/>gpgcheck=0<br/>enabled=1<br/>
+
| style="background-color: rgb(241, 241, 241);" | [nginx]<br />name=nginx repo<br />baseurl=http://nginx.org/packages/centos/$releasever/$basearch/<br />gpgcheck=0<br />enabled=1<br />
 
|}
 
|}
 
 
  
 
<span style="color:#0000FF;"><span style="font-size:larger;">'''Nginx 설치'''</span></span>
 
<span style="color:#0000FF;"><span style="font-size:larger;">'''Nginx 설치'''</span></span>
31번째 줄: 30번째 줄:
  
 
|}
 
|}
 
 
  
 
<span style="font-size:larger;"><span style="color:#0000FF;">'''Nginx 설정 파일'''</span></span>
 
<span style="font-size:larger;"><span style="color:#0000FF;">'''Nginx 설정 파일'''</span></span>
58번째 줄: 55번째 줄:
  
 
|}
 
|}
 
 
  
 
vi /etc/nginx/conf.d/default.conf
 
vi /etc/nginx/conf.d/default.conf
69번째 줄: 64번째 줄:
  
 
|}
 
|}
 
 
  
 
<span style="color:#0000FF;"><span style="font-size:larger;">'''방화벽 설정 및 서비스 기동'''</span></span>
 
<span style="color:#0000FF;"><span style="font-size:larger;">'''방화벽 설정 및 서비스 기동'''</span></span>
83번째 줄: 76번째 줄:
 
|}
 
|}
  
 +
브라우저에서 http://ossnode101.ossbiz.co.kr:80/ 으로 접속 합니다.
 +
 +
[[File:Nginx init.png|File:Nginx init.png]]
 +
 +
=== Windows에 nginx&nbsp;설치 ===
 +
 +
[http://nginx.org/en/download.html 다운로드 사이트]에서&nbsp;nginx-1.16.0.zip 파일을 다운로드 합니다.<br />c:/appl/nginx1160/ 폴더에 압축을 해제 합니다.
 +
 +
.
 +
cd  c:/appl/nginx1160/
 +
vi  conf/nginx.conf<br />&nbsp;&nbsp; &nbsp;worker_processes 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#--- core 수만큼 지정<br />&nbsp;&nbsp; &nbsp;gzip on;
 +
 +
<span style="line-height: 20.7999992370605px;"># nginx -s [ stop | quit | reopen | reload ]</span><br />start nginx
 +
 +
#--- http://localhost/ 로 접속하여 확인 한다.
 +
 +
PHP를 설치한 후 Factcgi 방식으로 PHP 실행하는 방법
 +
php-cgi  -b  127.0.0.1:9000
 +
 +
cd  c:/appl/nginx1160
 +
vi  conf/nginx.conf
 +
    location ~ \.php$ {
 +
        root          html;
 +
        fastcgi_pass  127.0.0.1:9000;
 +
        fastcgi_index  index.php;
 +
        include        fastcgi.conf;
 +
    }
 +
 +
./nginx  -s  reload
 +
#--- http://localhost/~.php 로 접속하여 확인 한다.
 +
 +
== Nginx 환경 설정 ==
 +
 +
=== Rewrite 사용법 ===
 +
 +
&nbsp;
 +
 +
rewrite 문법은 아래와 같이 단순 합니다.
 +
 +
문법&nbsp;: rewrite&nbsp; 정규표현식&nbsp; 대체문자열 [flag]
 +
 +
flag
 +
<ul style="box-sizing: border-box; margin: 0px 0px 20px 7px; padding-right: 0px; padding-left: 0px; border: 0px rgb(225, 225, 225); font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; font-size: 15px; line-height: inherit; font-family: Arial, Helvetica, Verdana, sans-serif; vertical-align: baseline; list-style: square outside; color: rgb(102, 102, 102);">
 +
<li>last&nbsp;: Rewrite 실행을 종료하고 변경된 URI로 다시 처리를 시작 합니다.</li>
 +
<li>break&nbsp;: Rewrite 처리를 종료 합니다. rewrite가 무한 반복 실행되는 것을 방지 합니다.</li>
 +
<li>redirect&nbsp;: 302 temporary redirect 처리를 합니다.</li>
 +
<li>permanent&nbsp;: 301 permanent redirect 처리를 합니다.</li>
 +
</ul>
 +
 +
요청된 parameter는 rewrite 처리후에 변경된 URI 뒤에 자동으로 붙습니다.
 +
 +
=== Mediawiki Rewrite Rule 적용 ===
 +
 +
Mediawiki를 사용할 때 URL rewrite 기능을 사용하면 편리한 점이 많습니다. 우선 긴 URL을 의미 있는 간단한 URL로 변경할 수 있고 폴더의 위치와 URL을 동일하게 유지할 필요도 없습니다.
 +
 +
&nbsp;
 +
 +
<span style="font-size:larger;">서버 환경과 요구 사항</span>
 +
 +
&nbsp;
 +
 +
서버 환경
 +
<ul style="list-style-type: square;">
 +
<li>Nginx 사용 중</li>
 +
<li>DOCUMENT_ROOT&nbsp;:&nbsp;/cloudnas/www/jopenbusiness/public_html/</li>
 +
<li>Mediawiki가 설치된 폴더&nbsp;:&nbsp;/cloudnas/www/jopenbusiness/public_html/mediawiki/</li>
 +
</ul>
 +
 +
&nbsp;
 +
 +
요구 사항
 +
<ul style="list-style-type: square;">
 +
<li>URL Rewrite 전&nbsp;:&nbsp;http://www.jopenbusiness.com/'''<span style="color: #008000;">mediawiki/index.php?title=SuiteCRM</span>'''</li>
 +
<li>URL Rewrite 후&nbsp;:&nbsp;http://www.jopenbusiness.com/<span style="color: #008000;">'''mediawiki/SuiteCRM'''</span></li>
 +
</ul>
 +
 +
&nbsp;
 +
 +
<span style="font-size:larger;">URL Rewrite 설정</span>
 +
 +
&nbsp;
 +
 +
vi&nbsp;&nbsp;/etc/nginx/sites-available/jopenbusiness.conf
 +
 +
{| style="width: 98%; margin: 2px 2px 2px 2px; border: 0px solid black; border-spacing: 0px; border-collapse: collapse; padding: 2px 2px 2px 16px;"
 +
|-
 +
| style="width: 10px; margin: 2px; border: 1px solid gray; border-spacing: 0px; border-collapse: collapse; padding: 2px; font-size: 8px; line-height: normal; color: black; background-color: gray; vertical-align: middle;" | &nbsp;
 +
| style="margin: 2px; border: 1px solid gray; border-spacing: 0px; border-collapse: collapse; padding: 2px 2px 2px 12px; font-size: 14px; line-height: normal; color: black; vertical-align: middle;" | location / {<br />'''<span style="color: #008000;">rewrite&nbsp; &nbsp; ^/mediawiki([^?]*)(?:\?(.*))?&nbsp; &nbsp; /mediawiki/index.php?title=$1&$2 last;</span>'''<br />index index.html index.htm index.php;<br />}
 +
|}
 +
 +
&nbsp;
 +
 +
vi&nbsp;&nbsp;/cloudnas/www/jopenbusiness/public_html/mediawiki/LocalSettings.php
 +
 +
{| style="width: 98%; margin: 2px 2px 2px 2px; border: 0px solid black; border-spacing: 0px; border-collapse: collapse; padding: 2px 2px 2px 16px;"
 +
|-
 +
| style="width: 10px; margin: 2px; border: 1px solid gray; border-spacing: 0px; border-collapse: collapse; padding: 2px; font-size: 8px; line-height: normal; color: black; background-color: gray; vertical-align: middle;" | &nbsp;
 +
| style="margin: 2px; border: 1px solid gray; border-spacing: 0px; border-collapse: collapse; padding: 2px 2px 2px 12px; font-size: 14px; line-height: normal; color: black; vertical-align: middle;" | $wgScriptPath = "/mediawiki";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#--- Mediawiki가 설치된 폴더<br /><span style="color: #008000;">$wgArticlePath = "/mediawiki/$1";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">#--- URL 호출 방법</span></span><br /><span style="color: #008000;">$wgUsePathInfo = true;</span>
 +
|}
 +
 +
&nbsp;
  
 +
<span style="font-size:larger;">참고 사이트</span>
 +
<ul style="list-style-type: square;">
 +
<li>https://www.mediawiki.org/wiki/Manual:Short_URL/wiki/Page_title_--_nginx_rewrite--root_access</li>
 +
<li>https://www.mediawiki.org/wiki/Manual:Short_URL/Apache</li>
 +
</ul>
  
브라우저에서 [http://ossnode101.ossbiz.co.kr:80/ http://ossnode101.ossbiz.co.kr:80/] 으로 접속 합니다.
+
&nbsp;
  
[[File:Nginx init.png|File:Nginx init.png]]
+
&nbsp;
  
 
== PHP 사용 설정 ==
 
== PHP 사용 설정 ==
98번째 줄: 197번째 줄:
 
yum install php php-*
 
yum install php php-*
  
mkdir /<span style="color: rgb(0, 0, 0); font-family: sans-serif; line-height: 19.5px; background-color: rgb(241, 241, 241);">var/lib/php/upload<br/>chown apache:apache /var/lib/php/upload</span>
+
mkdir /<span style="color: rgb(0, 0, 0); font-family: sans-serif; line-height: 19.5px; background-color: rgb(241, 241, 241);">var/lib/php/upload<br />chown apache:apache /var/lib/php/upload</span>
  
 
|}
 
|}
 
 
  
 
vi /etc/php.ini
 
vi /etc/php.ini
109번째 줄: 206번째 줄:
 
|-
 
|-
 
| style="background-color: rgb(241, 241, 241);" |  
 
| style="background-color: rgb(241, 241, 241);" |  
date.timezone = Asia/Seoul<br/>upload_tmp_dir &nbsp; &nbsp;= "/var/lib/php/upload"<br/>session.save_path = "/var/lib/php/session"
+
[PHP]<br />cgi.fix_pathinfo = 0<br />upload_tmp_dir =&nbsp;<span style="color: rgb(0, 0, 0); font-family: sans-serif; line-height: 20.8px; background-color: rgb(241, 241, 241);">"/var/lib/php/upload"</span><br />upload_max_filesize = 10M<br />post_max_size = 10M<br /><br />[Date]<br />date.timezone = Asia/Seoul<br /><br />[Session]<br />session.save_path =&nbsp;"/var/lib/php/session"
  
 
|}
 
|}
  
 
+
PHP-FPM (FastCGI Process Manager) 서비스를 실행 합니다
 
 
PHP-FPM 서비스를 실행 합니다
 
  
 
{| cellspacing="1" cellpadding="1" style="line-height: 20.7999992370605px; color: rgb(0, 0, 0); font-family: sans-serif; width: 771px;"
 
{| cellspacing="1" cellpadding="1" style="line-height: 20.7999992370605px; color: rgb(0, 0, 0); font-family: sans-serif; width: 771px;"
123번째 줄: 218번째 줄:
  
 
|}
 
|}
 
 
  
 
Site를 설정 합니다.
 
Site를 설정 합니다.
131번째 줄: 224번째 줄:
 
|-
 
|-
 
| style="background-color: rgb(241, 241, 241);" |  
 
| style="background-color: rgb(241, 241, 241);" |  
mkdir -p /nas/www/ossnode101/public_html<br/>mkdir -p /nas/www/ossnode101/logs<br/>chown -R apache:apache /srv/www/ossnode101
+
mkdir -p /nas/www/ossnode101/public_html<br />mkdir -p /nas/www/ossnode101/logs<br />chown -R apache:apache /srv/www/ossnode101
  
mkdir /etc/nginx/sites-available<br/>mkdir /etc/nginx/sites-enabled
+
mkdir /etc/nginx/sites-available<br />mkdir /etc/nginx/sites-enabled
  
 
cp /usr/share/nginx/html/* /nas/www/ossnode101/public_html
 
cp /usr/share/nginx/html/* /nas/www/ossnode101/public_html
  
 
|}
 
|}
 
 
  
 
vi /etc/nginx/nginx.conf
 
vi /etc/nginx/nginx.conf
146번째 줄: 237번째 줄:
 
|-
 
|-
 
| style="background-color: rgb(241, 241, 241);" |  
 
| style="background-color: rgb(241, 241, 241);" |  
&nbsp; &nbsp; include /etc/nginx/conf.d/*.conf;<br/>&nbsp; &nbsp; include /etc/nginx/sites-enabled/*.conf; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #--- 이 라인을 추가 합니다.
+
&nbsp; &nbsp; include /etc/nginx/conf.d/*.conf;<br />&nbsp; &nbsp; include /etc/nginx/sites-enabled/*.conf; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #--- 이 라인을 추가 합니다.
  
 
|}
 
|}
 
 
  
 
vi /etc/nginx/conf.d/default.conf
 
vi /etc/nginx/conf.d/default.conf
160번째 줄: 249번째 줄:
  
 
|}
 
|}
 
 
  
 
vi /etc/nginx/sites-available/ossnode101.conf
 
vi /etc/nginx/sites-available/ossnode101.conf
168번째 줄: 255번째 줄:
 
|-
 
|-
 
| style="background-color: rgb(241, 241, 241);" |  
 
| style="background-color: rgb(241, 241, 241);" |  
server {<br/>&nbsp; &nbsp; server_name ossnode101.ossbiz.co.kr;<br/>&nbsp; &nbsp; access_log /nas/www/ossnode101/logs/access.log;<br/>&nbsp; &nbsp; error_log /nas/www/ossnode101/logs/error.log;<br/>&nbsp; &nbsp; root /nas/www/ossnode101/public_html;
+
server {<br />&nbsp; &nbsp; server_name ossnode101.ossbiz.co.kr;<br />&nbsp; &nbsp; access_log /nas/www/ossnode101/logs/access.log;<br />&nbsp; &nbsp; error_log /nas/www/ossnode101/logs/error.log;<br />&nbsp; &nbsp; root /nas/www/ossnode101/public_html;
  
&nbsp; &nbsp; location / {<br/>&nbsp; &nbsp; &nbsp; &nbsp; index index.html index.htm index.php;<br/>&nbsp; &nbsp; }
+
&nbsp; &nbsp; location / {<br />&nbsp; &nbsp; &nbsp; &nbsp; index index.html index.htm index.php;<br />&nbsp; &nbsp; }
  
&nbsp; &nbsp; location ~ \.php$ {<br/>&nbsp; &nbsp; &nbsp; &nbsp; try_files $uri =404;<br/>&nbsp; &nbsp; &nbsp; &nbsp; include /etc/nginx/fastcgi_params;<br/>&nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass &nbsp;127.0.0.1:9000;<br/>&nbsp; &nbsp; &nbsp; &nbsp; fastcgi_index index.php;<br/>&nbsp; &nbsp; &nbsp; &nbsp; fastcgi_param SCRIPT_FILENAME /nas/www/ossnode/public_html$fastcgi_script_name;<br/>&nbsp; &nbsp; }<br/>}
+
&nbsp; &nbsp; location ~ \.php$ {<br />&nbsp; &nbsp; &nbsp; &nbsp; try_files $uri =404;<br />&nbsp; &nbsp; &nbsp; &nbsp; include /etc/nginx/fastcgi_params;<br />&nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass &nbsp;127.0.0.1:9000;<br />&nbsp; &nbsp; &nbsp; &nbsp; fastcgi_index index.php;<br />&nbsp; &nbsp; &nbsp; &nbsp; fastcgi_param SCRIPT_FILENAME /nas/www/ossnode/public_html$fastcgi_script_name;<br />&nbsp; &nbsp; }<br />}
  
 
|}
 
|}
 
 
  
 
sites-enabled에 ossnode101.conf를 추가 합니다.
 
sites-enabled에 ossnode101.conf를 추가 합니다.
186번째 줄: 271번째 줄:
  
 
|}
 
|}
 
 
  
 
vi&nbsp;/nas/www/ossnode101/public_html/phpinfo.php
 
vi&nbsp;/nas/www/ossnode101/public_html/phpinfo.php
194번째 줄: 277번째 줄:
 
|-
 
|-
 
| style="background-color: rgb(241, 241, 241);" |  
 
| style="background-color: rgb(241, 241, 241);" |  
<?php<br/>&nbsp; phpinfo
+
<?php<br />&nbsp; phpinfo();
  
 
?>
 
?>
  
 
|}
 
|}
 
 
  
 
nginx를 재기동 합니다.
 
nginx를 재기동 합니다.
213번째 줄: 294번째 줄:
 
|}
 
|}
  
<span style="color: rgb(0, 0, 0); font-family: sans-serif; line-height: 19.0499992370605px;">브라우저에서&nbsp;</span>[http://ossnode101.ossbiz.co.kr:80/phpinfo.php http://ossnode101.ossbiz.co.kr:80/phpinfo.php]<span style="color: rgb(0, 0, 0); font-family: sans-serif; line-height: 19.0499992370605px;">&nbsp;으로 접속 합니다.</span>
+
<span style="color: rgb(0, 0, 0); font-family: sans-serif; line-height: 19.0499992370605px;">브라우저에서&nbsp;</span>http://ossnode101.ossbiz.co.kr:80/phpinfo.php<span style="color: rgb(0, 0, 0); font-family: sans-serif; line-height: 19.0499992370605px;">&nbsp;으로 접속 합니다.</span>
  
 
== Tomcat 6 설정 ==
 
== Tomcat 6 설정 ==
224번째 줄: 305번째 줄:
 
&nbsp;yum install tomcat6 tomcat6-*
 
&nbsp;yum install tomcat6 tomcat6-*
  
cp /usr/share/tomcat6/webapps/ROOT/*.gif /nas/www/ossnode101/public_html<br/>cp /usr/share/tomcat6/webapps/ROOT/*.svg /nas/www/ossnode101/public_html<br/>cp /usr/share/tomcat6/webapps/ROOT/*.ico /nas/www/ossnode101/public_html
+
cp /usr/share/tomcat6/webapps/ROOT/*.gif /nas/www/ossnode101/public_html<br />cp /usr/share/tomcat6/webapps/ROOT/*.svg /nas/www/ossnode101/public_html<br />cp /usr/share/tomcat6/webapps/ROOT/*.ico /nas/www/ossnode101/public_html
  
 
|}
 
|}
 
 
  
 
vi /etc/nginx/sites-available/ossnode101.conf &nbsp; #--- 아래 항목을 추가 합니다.
 
vi /etc/nginx/sites-available/ossnode101.conf &nbsp; #--- 아래 항목을 추가 합니다.
235번째 줄: 314번째 줄:
 
|-
 
|-
 
| style="background-color: rgb(241, 241, 241);" |  
 
| style="background-color: rgb(241, 241, 241);" |  
&nbsp; &nbsp; location ~ \.do$ {<br/>&nbsp; &nbsp; &nbsp; proxy_pass &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[http://localhost:8080 http://localhost:8080];<br/>&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Real-IP $remote_addr;<br/>&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Forwarded-For $proxy_add_x_forwarded_for;<br/>&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;Host $http_host;<br/>&nbsp; &nbsp; }<br/>&nbsp; &nbsp; location ~ \.jsp$ {<br/>&nbsp; &nbsp; &nbsp; proxy_pass &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[http://localhost:8080 http://localhost:8080];<br/>&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Real-IP $remote_addr;<br/>&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Forwarded-For $proxy_add_x_forwarded_for;<br/>&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;Host $http_host;<br/>&nbsp; &nbsp; }<br/>&nbsp; &nbsp; location ^~/servlets/* {<br/>&nbsp; &nbsp; &nbsp; proxy_pass &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[http://localhost:8080 http://localhost:8080];<br/>&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Real-IP $remote_addr;<br/>&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Forwarded-For $proxy_add_x_forwarded_for;<br/>&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;Host $http_host;<br/>&nbsp; &nbsp; }
+
&nbsp; &nbsp; location ~ \.do$ {<br />&nbsp; &nbsp; &nbsp; proxy_pass &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://localhost:8080;<br />&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Real-IP $remote_addr;<br />&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Forwarded-For $proxy_add_x_forwarded_for;<br />&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;Host $http_host;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; location ~ \.jsp$ {<br />&nbsp; &nbsp; &nbsp; proxy_pass &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://localhost:8080;<br />&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Real-IP $remote_addr;<br />&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Forwarded-For $proxy_add_x_forwarded_for;<br />&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;Host $http_host;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; location ^~/servlets/* {<br />&nbsp; &nbsp; &nbsp; proxy_pass &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://localhost:8080;<br />&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Real-IP $remote_addr;<br />&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;X-Forwarded-For $proxy_add_x_forwarded_for;<br />&nbsp; &nbsp; &nbsp; proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp;Host $http_host;<br />&nbsp; &nbsp; }
  
 
|}
 
|}
 
 
  
 
<span style="color: rgb(0, 0, 255);"><span style="font-size: larger;">'''방화벽 설정 및 서비스 기동'''</span></span>
 
<span style="color: rgb(0, 0, 255);"><span style="font-size: larger;">'''방화벽 설정 및 서비스 기동'''</span></span>
252번째 줄: 329번째 줄:
 
|}
 
|}
  
 
+
http://ossnode101.ossbiz.co.kr/index.jsp 사이트로 접속하여 Tomcat 화면을 표시해 봅니다.
 
 
[http://ossnode101.ossbiz.co.kr/index.jsp http://ossnode101.ossbiz.co.kr/index.jsp] 사이트로 접속하여 Tomcat 화면을 표시해 봅니다.
 
  
 
== Nginx에 UTF-8 설정 ==
 
== Nginx에 UTF-8 설정 ==
263번째 줄: 338번째 줄:
  
 
== 관리자 가이드 ==
 
== 관리자 가이드 ==
 +
 +
=== 업로드 파일 크기 변경 ===
 +
 +
vi /etc/php.ini
 +
 +
{| cellspacing="1" cellpadding="1" style="font-size: 14px; color: rgb(37, 37, 37); font-family: sans-serif; line-height: 20.7999992370605px; width: 771px;"
 +
|-
 +
| style="background-color: rgb(241, 241, 241);" |
 +
post_max_size = 10M<br />upload_max_filesize = 10M
 +
 +
|}
 +
 +
vi /etc/nginx/sites-available/jopenbusiness.conf
 +
 +
{| cellspacing="1" cellpadding="1" style="font-size: 14px; color: rgb(37, 37, 37); font-family: sans-serif; line-height: 20.7999992370605px; width: 771px;"
 +
|-
 +
| style="background-color: rgb(241, 241, 241);" |
 +
client_max_body_size 10M; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#--- server, location, http 내에 설정할 수 있습니다.
 +
 +
|}
 +
 +
=== Server를 domain에 연결 ===
 +
http://docs.jopenbusiness.com/ 요청을 http://docs.jopenbusiness.com:4000/ 서비스로 연결 합니다. server를 domain으로 구분하고 proxy_pass를 사용하여 4000 port로 연결 합니다.
 +
 +
    server {
 +
        listen      80;
 +
        server_name  docs.jopenbusiness.com docs.obcon.biz docs.obcon.co.kr;    #--- domain과 연결
 +
        root        /work/appl/obcon_scada/manual;
 +
        charset      UTF-8;
 +
 +
        location / {
 +
            proxy_no_cache 1;
 +
            proxy_pass  http://127.0.0.1:4000;                                  #--- 다른 서비스 호출
 +
        }
 +
    }
  
 
== 참고 문헌 ==
 
== 참고 문헌 ==

2019년 8월 1일 (목) 18:00 기준 최신판

비동기 이벤트 기반의 Web Server인 nginx를 정리 합니다.

nginx 개요

Nginx 설치

CentOS 6.5에 nginx 설치

Nginx 저장소 생성

vi /etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

Nginx 설치

yum install nginx

Nginx 설정 파일

  • /etc/nginx/ : 설정 파일 폴더
    • nginx.conf
    • conf.d/
  • /var/log/nginx/ : 로그 폴더
    • access.log
    • error.log
  • /usr/share/nginx/html/ : Document Root 폴더


기본 설정

vi /etc/nginx/nginx.conf

worker_processes 1;                #--- core 수만큼 지정

gzip on;

vi /etc/nginx/conf.d/default.conf

server_name  ossnode101.ossbiz.co.kr;

방화벽 설정 및 서비스 기동

setup                                 #--- 방화벽에서 80/tcp port를 오픈 합니다.

service nginx restart

브라우저에서 http://ossnode101.ossbiz.co.kr:80/ 으로 접속 합니다.

File:Nginx init.png

Windows에 nginx 설치

다운로드 사이트에서 nginx-1.16.0.zip 파일을 다운로드 합니다.
c:/appl/nginx1160/ 폴더에 압축을 해제 합니다.

.

cd  c:/appl/nginx1160/
vi  conf/nginx.conf
    worker_processes 1;                #--- core 수만큼 지정
    gzip on; # nginx -s [ stop | quit | reopen | reload ]
start nginx #--- http://localhost/ 로 접속하여 확인 한다.

PHP를 설치한 후 Factcgi 방식으로 PHP 실행하는 방법

php-cgi  -b  127.0.0.1:9000

cd  c:/appl/nginx1160
vi  conf/nginx.conf
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi.conf;
    }

./nginx  -s  reload
#--- http://localhost/~.php 로 접속하여 확인 한다.

Nginx 환경 설정

Rewrite 사용법

 

rewrite 문법은 아래와 같이 단순 합니다.

문법 : rewrite  정규표현식  대체문자열 [flag]

flag

  • last : Rewrite 실행을 종료하고 변경된 URI로 다시 처리를 시작 합니다.
  • break : Rewrite 처리를 종료 합니다. rewrite가 무한 반복 실행되는 것을 방지 합니다.
  • redirect : 302 temporary redirect 처리를 합니다.
  • permanent : 301 permanent redirect 처리를 합니다.

요청된 parameter는 rewrite 처리후에 변경된 URI 뒤에 자동으로 붙습니다.

Mediawiki Rewrite Rule 적용

Mediawiki를 사용할 때 URL rewrite 기능을 사용하면 편리한 점이 많습니다. 우선 긴 URL을 의미 있는 간단한 URL로 변경할 수 있고 폴더의 위치와 URL을 동일하게 유지할 필요도 없습니다.

 

서버 환경과 요구 사항

 

서버 환경

  • Nginx 사용 중
  • DOCUMENT_ROOT : /cloudnas/www/jopenbusiness/public_html/
  • Mediawiki가 설치된 폴더 : /cloudnas/www/jopenbusiness/public_html/mediawiki/

 

요구 사항

 

URL Rewrite 설정

 

vi  /etc/nginx/sites-available/jopenbusiness.conf

  location / {
rewrite    ^/mediawiki([^?]*)(?:\?(.*))?    /mediawiki/index.php?title=$1&$2 last;
index index.html index.htm index.php;
}

 

vi  /cloudnas/www/jopenbusiness/public_html/mediawiki/LocalSettings.php

  $wgScriptPath = "/mediawiki";                                   #--- Mediawiki가 설치된 폴더
$wgArticlePath = "/mediawiki/$1";                           #--- URL 호출 방법
$wgUsePathInfo = true;

 

참고 사이트

 

 

PHP 사용 설정

PHP를 설치 합니다.

yum install php php-*

mkdir /var/lib/php/upload
chown apache:apache /var/lib/php/upload

vi /etc/php.ini

[PHP]
cgi.fix_pathinfo = 0
upload_tmp_dir = "/var/lib/php/upload"
upload_max_filesize = 10M
post_max_size = 10M

[Date]
date.timezone = Asia/Seoul

[Session]
session.save_path = "/var/lib/php/session"

PHP-FPM (FastCGI Process Manager) 서비스를 실행 합니다

service php-fpm restart

Site를 설정 합니다.

mkdir -p /nas/www/ossnode101/public_html
mkdir -p /nas/www/ossnode101/logs
chown -R apache:apache /srv/www/ossnode101

mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled

cp /usr/share/nginx/html/* /nas/www/ossnode101/public_html

vi /etc/nginx/nginx.conf

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*.conf;               #--- 이 라인을 추가 합니다.

vi /etc/nginx/conf.d/default.conf

   server_name  nouse.ossbiz.co.kr;

vi /etc/nginx/sites-available/ossnode101.conf

server {
    server_name ossnode101.ossbiz.co.kr;
    access_log /nas/www/ossnode101/logs/access.log;
    error_log /nas/www/ossnode101/logs/error.log;
    root /nas/www/ossnode101/public_html;

    location / {
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /nas/www/ossnode/public_html$fastcgi_script_name;
    }
}

sites-enabled에 ossnode101.conf를 추가 합니다.

    ln -s /etc/nginx/sites-available/ossnode101.conf /etc/nginx/sites-enabled/ossnode101.conf

vi /nas/www/ossnode101/public_html/phpinfo.php

<?php
  phpinfo();

?>

nginx를 재기동 합니다.

service php-fpm restart

 service nginx restart

브라우저에서 http://ossnode101.ossbiz.co.kr:80/phpinfo.php 으로 접속 합니다.

Tomcat 6 설정

Apache Tomcat 설치

 yum install tomcat6 tomcat6-*

cp /usr/share/tomcat6/webapps/ROOT/*.gif /nas/www/ossnode101/public_html
cp /usr/share/tomcat6/webapps/ROOT/*.svg /nas/www/ossnode101/public_html
cp /usr/share/tomcat6/webapps/ROOT/*.ico /nas/www/ossnode101/public_html

vi /etc/nginx/sites-available/ossnode101.conf   #--- 아래 항목을 추가 합니다.

    location ~ \.do$ {
      proxy_pass              http://localhost:8080;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        Host $http_host;
    }
    location ~ \.jsp$ {
      proxy_pass              http://localhost:8080;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        Host $http_host;
    }
    location ^~/servlets/* {
      proxy_pass              http://localhost:8080;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        Host $http_host;
    }

방화벽 설정 및 서비스 기동

setup                                 #--- 방화벽에서 8080/tcp port를 오픈 합니다.

service tomcat6 restart

http://ossnode101.ossbiz.co.kr/index.jsp 사이트로 접속하여 Tomcat 화면을 표시해 봅니다.

Nginx에 UTF-8 설정


관리자 가이드

업로드 파일 크기 변경

vi /etc/php.ini

post_max_size = 10M
upload_max_filesize = 10M

vi /etc/nginx/sites-available/jopenbusiness.conf

client_max_body_size 10M;                  #--- server, location, http 내에 설정할 수 있습니다.

Server를 domain에 연결

http://docs.jopenbusiness.com/ 요청을 http://docs.jopenbusiness.com:4000/ 서비스로 연결 합니다. server를 domain으로 구분하고 proxy_pass를 사용하여 4000 port로 연결 합니다.

   server {
       listen       80;
       server_name  docs.jopenbusiness.com docs.obcon.biz docs.obcon.co.kr;    #--- domain과 연결
       root         /work/appl/obcon_scada/manual;
       charset      UTF-8;

       location / {
           proxy_no_cache 1;
           proxy_pass  http://127.0.0.1:4000;                                  #--- 다른 서비스 호출
       }
   }

참고 문헌