Tomcat behind ssl Nginx reverse proxy
Настройка Nginx:
map $scheme $port { default 80; http 80; https 8443; } server { listen 80; listen 443 ssl; server_name _; ssl_certificate /etc/nginx/ssl/chained-cert.crt; ssl_certificate_key /etc/nginx/ssl/sslkey.key; ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-For $remote_addr; location / { proxy_pass http://127.0.0.1:$port; } }
Настройка tomcat:
в server.xml
добавить:
<Connector port="8443" protocol="HTTP/1.1" scheme="https" proxyPort="443" secure="true" />
Для отображения в логе реальных IP добавить:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" remoteIpHeader="X-Forwarded-For" requestAttributesEnabled="true" internalProxies="127\.0\.0\.1" pattern=" %{X-Forwarded-For}i %l %u %t "%r" %s %b" />
Enjoy!