내가 보려고 모아놓는 Nginx + tomcat9 연동
- Centos 6.9 환경 / Centos 7은 명령어가 달라서 다른 글을 찾아보시는 게 좋아요!


1. vi /etc/nginx/nginx.conf > http {} 안에 추가 

    upstream tomcat {
        server 127.0.0.1:8080;
    }

    server {
      listen 80;
      server_name localhost;    // 도메인이 있다면 이 부분을 변경해주면 됨

      location / {
          proxy_pass http://tomcat;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }

      location ~* \.(gif|jpg|png|js|css) {
          access_log off;
          proxy_pass http://tomcat;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
    }

 

[vi /etc/nginx/nginx.conf 전체 소스]

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    upstream tomcat {
        server 127.0.0.1:8080;
    }

    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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    server {
      listen 80;
      server_name localhost;    // 도메인이 있다면 이 부분을 변경해주면 됨

      location / {
          proxy_pass http://tomcat;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }

      location ~* \.(gif|jpg|png|js|css) {
          access_log off;
          proxy_pass http://tomcat;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
    }

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

 

[ip]:8080에 tomcat이 구동된 상태에서 [ip]로 접근하게 되면 정상적으로 붙는 걸 확인 할 수 있다.

[// 도메인이 있다면 이 부분을 변경해주면 됨] 에 도메인으로 설정해주었다면

도메인으로 접근해도 정상적으로 화면이 노출된다.

 

nginx + tomcat 연동 끝- 

'개발자' 카테고리의 다른 글

아, 뭐해먹고 살아야 할까요? 서른 개발자.  (0) 2020.08.04
Nginx SSL 적용 http https 리다이렉트/리디랙션 처리  (0) 2020.05.11
Nginx 설치 - Centos 6.9 환경  (0) 2020.05.08
JSTL 부등호 gt lt eq  (0) 2019.08.09
Quartz  (0) 2019.05.30

+ Recent posts