Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

keystoreFile 항목을 keystore의 위치로 수정하거나, 만들어진 keystore파일을 tomcat이 접근 가능한 위치로 옮깁니다.

이제 톰캣을 싱행시키고 실행시키고 localhost:8443으로 접속했을때, domain이 맞지 않다고 에러가 뜨고에러페이지가 보이고, 접속을 감행했을 때 톰캣이 뜨면 성공입니다.

 

nginx 설정하기

보안을 위해 80과 443포트만 열어둔 경우, 톰캣으로 리다이렉션해주는 설정을 해야 한다.

nginx.conf에 아래와 같은 설정을 추가합니다.

server {
  listen 80;
  server_name (your domain);
  return 301 https://$server_name$request_uri;
}

server {
  listen 443;
  server_name (your domain);

  ssl on;
  ssl_certificate (path to certification file)
  ssl_certificate_key (path to certification key file)

  location / {
    proxy_pass https://localhost:8443;
    index index.html;
  }
}

Tomcat에서 redirect 설정하기

http://tkurek.blogspot.kr/2013/07/tomcat-7-http-to-https-redirect.html

톰캣 기본 설정은 HTTP를 위해 8080 포트를,

HTTPS를 위해 8443 포트를 사용합니다.

 

톰캣에서 8080으로 들어오는 요청을 8443으로 돌리는 방법은 다음과 같습니다.

server.xml 업데이트

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           URIEncoding="UTF-8"
           redirectPort="8443" />
8080 포트 설정을 아래와 같이 바꿉니다.
<Connector port="8080" enableLookups="false"
           redirectPort="8443" />

web.xml 업데이트

</web-app> 끝나는 태그 직전에 아래의 마크업을 붙여넣습니다.

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Protected Context</web-resource-name>
    <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <!-- auth-constraint goes here if you requre authentication -->
  <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>