Nginx as a reverse proxy to a Tomcat instance via the HTTP connector

12,422

Solution 1

Yeah, that'll work just fine.

From the tag, I'm guessing you're using an AJP connector right now? You'll just need to make sure that your HTTP listener is working right; otherwise, there should be no problem. Nginx works great as a reverse proxy.

Solution 2

Shouldn't run into any problems. I have that setup right now. Here's a modified version nginx conf that shows it's pretty straightforward.

server {
        listen      80;
        server_name server.example.com;
        rewrite     ^(.*)   https://$server_name$1 permanent;
}

server {
        listen   443;

        server_name  server.example.com server;

        ssl  on;
        ssl_certificate  /certs/ssl.crt;
        ssl_certificate_key  /certs/ssl.key;

        ssl_session_timeout  5m;

        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;


        access_log  /var/log/nginx/access.log;

        location / {
            proxy_pass  http://127.0.0.1:8080/;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

            client_max_body_size       10m;
            client_body_buffer_size    128k;

            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;

            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
        }
}
Share:
12,422

Related videos on Youtube

Filip Dupanović
Author by

Filip Dupanović

A colorful individual apt in the use of technology for social progress; exerting passion for people—hardly ever flabbergasted by anyone's occasional demotion from rationale; oft loves sharing great new comedic material in the ongoing joke… Feel free to make the best use of snippets I post, just be careful! Thank you 🙇: 3D5R7qtd7RR1qrc6JokiNSRbSit5Yg671h

Updated on September 18, 2022

Comments

  • Filip Dupanović
    Filip Dupanović over 1 year

    I'm dropping Apache as a reverse proxy to a Tomcat instance, mainly because it has no other purpose other than forwarding requests to the Tomcat instance.

    I'm no expert at deploying Java Web applications with Tomcat and I'm wondering if I'm running in for a nasty surprise if I use Nginx to forward requests to the HTTP connector?

  • Filip Dupanović
    Filip Dupanović about 13 years
    Yeah, your right, thanks. I was previously communicating via AJP and I had concerns about sessions and response headers, but everything seems to be working fine--faster even!