Tomcat X Nginx: Reverse Proxy
Posted on
Tomcat7 di Centos 7 tidak bisa bind port 80. Lagipula, bukan best practice serve langsung pakai tomcat. Oleh sebab itu, di depan tomcat harus ada web server lain, bisa apache httpd, bisa juga Nginx. Artikel ini hanya akan berisi snipset konfigurasi reverse proxy tomcat pakai nginx.
Snipset Nginx vhost:
###
# Desc: Nginx reserve proxy untuk aplikasi servlet tomcat
# Author: Sumarsono
# Create date: 2019-01-08
# Tested: Yes
##
server {
listen 80;
server_name sub.domain.tld;
error_log /var/log/nginx/sub/error.log warn;
access_log /var/log/nginx/sub/access.log combined;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}
}
Snipset server.xml:
...
<Engine name="Catalina" defaultHost="localhost">
<Valve className="org.apache.catalina.valves.RemoteIpValve"
internalProxies="127\.0\.[0-1]\.1"
remoteIpHeader="x-forwarded-for"
requestAttributesEnabled="true"
protocolHeader="x-forwarded-proto"
protocolHeaderHttpsValue="https"/>
...
Selesai.