1. tomcat/conf/server.xml 에 access log 생성 관련 추가

<Server port="8015" shutdown="SHUTDOWN">
  <Service name="Catalina">
  ...
      <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
        ...
          
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b %D" />
            
            
       </Host>
   </Service>
</Server>

- 위 내용처럼 <Host> 태그 및 에 <Value> 태그를 생성

- prefix , suffix 설정하면  /logs 폴더 및에 파일 생성

- pattern은 아래 내용 확인 ( 자세히 : https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/AccessLogValve.html )

%a - Remote IP address
%A - Local IP address
%b - Bytes sent, excluding HTTP headers, or '-' if no bytes were sent
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if enableLookups for the connector is false)
%H - Request protocol
%l - Remote logical username from identd (always returns '-')
%m - Request method
%p - Local port
%q - Query string (prepended with a '?' if it exists, otherwise an empty string
%r - First line of the request
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format format
%u - Remote user that was authenticated
%U - Requested URL path
%v - Local server name
%D - Time taken to process the request, in millis
%T - Time taken to process the request, in seconds
%I - current Request thread name (can compare later with stacktraces)

결과: 

// pattern="%h %l %u %t &quot;%r&quot; %s %b %D"

127.0.0.1   -    -    [04/Sep/2023:00:00:13 +0900] "GET /sse HTTP/1.1"  200   43   11  
   (%h)    (%l) (%u)              (%t)                   (%r)           (%s) (%b) (%D)

- 중요부분만 보면 /sse 라는 GET 방식 API 요청 결과 , 성공(200) 했고 ,헤더 포함 43byte 전송.

- 요청 소요 시간은 11 (millesec) .

'server > tomcat' 카테고리의 다른 글

Tomcat SSL 인증서 적용  (0) 2023.02.20

tomcat 버전 : 9.0

java 버전 :  8 (1.8.065)

 

OpenSSL 설치 (https://takudaddy.tistory.com/507)

 

.crt  -> .pfx  -> .jks  순서로 변경
편의상 인증서 파일이 있는 경로에서 cmd 창으로 작업하는 것을 추천
아래는 인증서 파일이 D:/ 루트에 있을 경우

1. 인증서 파일(.crt)을 .jks로 변환

 

D:\>openssl pkcs12 -export -name (도메인이름) -in (인증서파일_이름).crt -inkey 
(개인키 파일 이름).key -out (생성할 pfx 파일 이름).pfx

Loading 'screen' into random state - done
Enter Export Password: (패스워드 입력)
Verifying - Enter Export Password: (패스워드 확인)
unable to write 'random state'

ex) openssl pkcs12 -export  -name goom.tistory.com -in goom_tistory_com.crt -inkey 
goom_tistory_com.key -out goom_tistory_com.pfx

 

 

2..pfx 파일을 .jks 파일로 변환

D:\>keytool -importkeystore -srckeystore (위에서 생성한 pfx 파일 이름).pfx -srcstoretype pkcs12 
-destkeystore (생성할 jks파일 이름).jks -deststoretype jks
대상 키 저장소 비밀번호 입력: (jks에 적용할 패스워드 입력)
새 비밀번호 다시 입력: (패스워드 확인)
소스 키 저장소 비밀번호 입력: (pfx 생성시 설정한 패스워드)
portal.sangsin.com 별칭에 대한 항목이 성공적으로 임포트되었습니다.
임포트 명령 완료: 성공적으로 임포트된 항목은 1개, 실패하거나 취소된 항목은 0개입니다.

ex) keytool -importkeystore -srckeystore goom_tistory_com.pfx  -srcstoretype pkcs12 
-destkeystore goom_tistory_com.jks -deststoretype jks

 

더보기

[참고] 확장자별 사용 가능한 서버
Apache 서버 : .crt, .pem 확장자 적용 가능
Nginx 서버 : .crt, .pem 확장자 적용 가능
Webtob 서버 : .crt, .pem 확장자 적용 가능
IIS 서버 : .pfx 확장자 적용 가능
Exchange 서버 : .pfx 확장자 적용 가능
Tomcat 서버 : .jks 확장자 적용 가능
Resin 서버 : .jks 확장자 적용 가능
Jboss 서버 : .jks 확장자 적용 가능

* 위의 내용은 일반적인 사항이며,
인증서 갱신 시에는 서버에 설치 되어 있는 확장자를 확인 후 서버에 설치되어 있는 확장자와
동일한 인증서 파일로 설치 진행하면 됨.

3.Tomcat / server.xml에 적용

 

<Server port="8005" shutdown="SHUTDOWN">
	<Service name="Catalina">
    	<Connector port="80" protocol="HTTP/1.1"
        		redirectPort="443"
                ...
                />
         <Connector protocol="org.apache.coyote.http11.Http11NioProtocol"
                port="443"
                scheme="https"
                secure="true"
                SSLEnabled="true"
                keystoreFile="(.jsk 경로 및 파일 이름)"
                keystorePass="(생성시 설정한 패스워드)"
                sslProtocol="SSL" 
           />
           ...
       </Service>
 </Server>

 

4. http -> https 자동 리다이렉트

 

- 브라우저 창에 http:// 로 입력해도 자동으로 https:// 변환 필요

 

- tomcat/conf/web.xml 에 아래 코드 삽입

	...
    
	<!-- SSL Forward(HTTP->HTTPS) config start -->
	<security-constraint>
	<web-resource-collection>
	<web-resource-name>SSL Forward</web-resource-name>
	<url-pattern>/*</url-pattern>
	</web-resource-collection>
	<user-data-constraint>
	<transport-guarantee>CONFIDENTIAL</transport-guarantee>
	</user-data-constraint>
	</security-constraint>
	<security-constraint>
	<web-resource-collection>
	<web-resource-name>HTTPS or HTTP</web-resource-name>
	<url-pattern>/js/*</url-pattern>
	<url-pattern>/images/*</url-pattern>
	<url-pattern>/css/*</url-pattern>
	<url-pattern>/plugins/*</url-pattern>
	</web-resource-collection>
	<user-data-constraint>
	<transport-guarantee>NONE</transport-guarantee>
	</user-data-constraint>
	</security-constraint>
	<!-- SSL Forward(HTTP->HTTPS) config end -->
    
</web-app>

 

[참고]

tomcat 로그에 별 특이 사항 없고 정상적으로 올라온 것 같을 때 확인해 볼 사항

 

1. tomcat/log의 catalina.log 

 - 톰캣 실행되면서 특이한 로그 없는지 확인

 

2.server.xml 에 ssl 인증서 경로 확인

 

3.방화벽 확인

 - AP 서버에서 톰캣 구동 후 telnet 등으로 443 포트 연결되는지 확인

 - AP 서버는 되는데 외부에서 연결이 안되면 방화벽 문제

 - 직접 방화벽 허용이 가능하면 ufw allow 443 등으로 방화벽 허용

'server > tomcat' 카테고리의 다른 글

톰캣 access log 응답 시간 조회  (0) 2023.09.04

+ Recent posts