Prerequisites:
(1) Tomcat is installed and can be started successfully.
(2) installed Nginx, and can successfully start
The next configuration:
(1) Add two files to the Nginx Conf folder as follows: (after the new file, copy the code directly)
File 1:proxy.conf
proxy_redirect off;proxy_set_header Host $host;p roxy_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 -;p roxy_send_timeout -;p roxy_read_timeout -;p roxy_buffer_size 4k;proxy_buffers432k;proxy_busy_buffers_size 64k;proxy_temp_file_write_size 64k;gzipOn;gzip_min_length +; gzip_types text/plain Text/css Application/x-javascript;
proxy.conf
File 2:gzip.conf
gzip on;gzip_min_length gzip_types text/plain text/css application/ X-javascript;
gzip.conf
(2) Modify the nginx.conf file, add the code in http{(below)}:(note: Tomcat's open port is set to 12337 in advance, the following code with Nginx 8085来 proxy)
include gzip .conf; Upstream localhost {#ip_hash #ip_hash; Server localhost: 12337 ; } server {Listen 8085 ; server_name localhost; Location / {proxy_connect_timeout 3 ; Proxy_send_timeout 30 ; Proxy_read_timeout 30 ; Proxy_pass http: // localhost;
View Code
(3) If you want to set up tomcat separation, the access to the static page does not need to enter Tomcat
For example: Name the folder where the static pages are stored as static, and the path is e:/static
Then the new code of Step (2) to do the following processing, add code as follows:
Includegzip. conf; Upstream localhost {#ip_hash #ip_hash; Server localhost:12337; # server localhost:12111; #可配置多个端口} server {Listen8085; server_name localhost; #设定访问静态文件直接读取不经过tomcat Location~ .*\. (gif|jpg|jpeg|png|bmp| swf) $ {root E:\static; Expires 30d; } location ~. *\. (JS|CSS)? $ {root E:\static; Expires 1h; } Location/{proxy_connect_timeout3; Proxy_send_timeout -; Proxy_read_timeout -; Proxy_pass http://localhost; } }
After the configuration is complete, start Tomcat, and then start the Nginx
Final effect: Access the same content as the 127.0.0.1:8085 and 127.0.0.1:12337 pages.
Reference Links:
Http://www.cnblogs.com/super-d2/p/3662215.html
Http://www.cnblogs.com/hughtxp/p/4323875.html
Nginx+tomcat Configuration under Nginx--windows environment (including static and dynamic separation)