Nginx reverse proxy Tomcat

Source: Internet
Author: User
Tags nginx reverse proxy

System Environment: centos

Production Environment: wdlinux

Web engine: nginx + Apache

1. Create a VM in Tomcat

Modify Tomcat \ conf \ Server. xml and add the

<Host name="www.abc.com" appBase="/www/webapps" unpackWARS="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">    <Context docBase="/www/webapps/abc" path=""reloadable="true" sessionCookiePath="/" /></Host>

2. Enable reverse proxy in nginx

2. 1. Open the wdlinux/nginx-xxx/CONF/nginx. conf file and add include vhost/*. conf to the last line in the HTTP curly brackets.

2. Create proxy. conf in the nginx-xxx/conf folder and add the following content to the file:

 1 proxy_connect_timeout 30s; 2 proxy_send_timeout   90; 3 proxy_read_timeout   90; 4 proxy_buffer_size    32k; 5 proxy_buffers     4 32k; 6 proxy_busy_buffers_size 64k; 7 #proxy_redirect     off; 8 proxy_hide_header  Vary; 9 proxy_set_header   Accept-Encoding ‘‘;10 proxy_set_header   Host   $host;11 proxy_set_header   Referer $http_referer;12 proxy_set_header   Cookie $http_cookie;13 proxy_set_header   X-Real-IP  $remote_addr;14 proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

2. 3. Create abc_com.conf in the nginx-xxx/CONF/vhost folder and add the following content to the file:

 1     server { 2         listen       80; 3         server_name  www.abc.com; 4         root /www/webapps/abc; 5         index index.html index.htm; 6  7         location / { 8                   proxy_pass http://localhost:81; 9                   proxy_cookie_path /abc/ /;10                   include proxy.conf;11         }12         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {13                 expires      30d;14         }15 16         location ~ .*\.(js|css)?$ {17                 expires      12h;18         }19     }

After the configuration is complete, restart the service to access the ABC project through www.abc.com.

PS: The nginx service must be restarted using the command line method, that is, nginx-xxx/sbin/nginx-s reload.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.