개발환경
nginx : 1.2.2
tomcat : 7
step 1. nginx download
nginx의 설치는 다운로드 후 압축만 풀면 끝이기 때문에 따로 설치는 없습니다.
Download URL : http://www.nginx.org/en/download.html
[ 그림 1 ] nginx download
step 2. 압축해제
다운받은 nginx-1.2.2.zip 파일 압축을 풀고 nginx를 실행합니다.
[ 그림 2 ] nginx 실행
browser 에서 http://localhost 로 접속하여 확인.
[ 그림 3 ] nginx web browser 확인
step 3. nginx 종료하기
작업관리자에서 kill하는 방법도 있지만 cmd 에서 종료합니다.
[ 그림 4 ] nginx 종료
step 4. tomcat download
톰캣을 다운받아 압축을 해제합니다.
Download URL : http://tomcat.apache.org/download-70.cgi
1. tomcat icon 실행
[ 그림 5 ] tomcat Install
[ 그림 6 ] tomcat Install
[ 그림 7 ] tomcat Install
[ 그림 8 ] tomcat Install
[ 그림 9 ] tomcat Install
[ 그림 10 ] tomcat Install
[ 그림 11 ] tomcat Install
[ 그림 12 ] tomcat Install
step 5. tomcat 구동 및 종료
아래의 도구모음 확인
[ 그림 13 ] tomcat 모니터링 툴
web browser에서 http://localhost:8080 접속 확인
[ 그림 14 ] tomcat 구동 확인
step 6. ngix + tomcat 연동
reverse proxy 방식의 톰캣 연동 설정 ( jsp로 오는 요청은 tomcat으로 proxy 합니다. )
conf/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;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
location ~ \.(css|js|jpg|jpeg|gif|html|html|swf)$ {
root /var/www;
index index.html index.htm;
}
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;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
step 7. 연동 테스트
browser를 열고 http://localhost/index.html 접속
[ 그림 15 ] index.html 요청시
browser를 열고 http://localhost/index.jsp 접속 ( 이미지, css, js 는 nginx의 Document Root 를 보기때문에 로딩이 안되는 것을 확인 할 수 있습니다.)
[ 그림 16 ] index.jsp 요청시