Simple nginx and tomcat load configuration (in windows)

Source: Internet
Author: User
Tags password protection

 

This article describes a simple configuration instance of nginx and tomcat in windows, including the js special configuration of dwr. Of course, nginx can only show good performance under unix, mainly in io model and other aspects.

 

Download the project demo:/Files/freeman1984/ndemo.rar, which contains a simple test project and configuration file, as well as a reference document for nginx.

 

Project access path in tomcat is: http: // localhost: 8088/ndemo/server. jsp

 

Nginx access path: http://www.joe.com/server.jsp, where (www.joe.com is configured in the hosts file)

 

 

Here is the nginx Configuration:

 

 

Nginx. conf content:

 

 

 

# User nobody;

 

Worker_processes 2; # Number of processes, which is related to the number of CPUs

 

Pid logs/nginx. pid;

 

Events {

 

Worker_connections 1024; # Number of connections supported by each process

 

}

 

 

 

Http {

 

Include mime. types;

 

Default_type application/octet-stream;

 

# Log Part

 

Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'

 

'$ Status $ body_bytes_sent "$ http_referer "'

 

'"$ Http_user_agent" "$ http_x_forwarded_for "';

 

Sendfile on;

 

 

Keepalive_timeout 65;

 

 

 

Include gzip. conf; # Start Data Compression

 

 

 

 

Server {

 

Listen 80;

 

Server_name www.joe.com; # this part of the test can be added to the host file

 

Root E: \ apache-tomcat-6.0.32 \ webapps; # project path. Use a directory directly with the background.

 

Error_page 404/ndemo/404.html;

 

Error_page 500 502 503/ndemo/50x.html;

 

 

Location ~ ^/(WEB-INF )/{

 

Deny all;

 

}

 

# This part mainly refers to the fact that dwr's js Code is dynamically generated by the server and cannot be handed over to nginx for processing. In this case, 404 occurs and needs to be processed separately and handed over to the server for processing.

 

Location/ndemo/dwr /{

 

Proxy_pass http: // localhost: 8088/ndemo/dwr /;

 

Include proxy. conf;

 

}

 

# Other static file processing methods for dwr are handed over to nginx for processing.

 

Location ~ \.

 

 

(Htm | html | gif | jpg | jpeg | png | ico | rar | css | js | zip | txt | flv | swf | doc | ppt | xls | pdf) $ {

 

Access_log off;

 

Expires 24 h;

 

}

 

# Note that my context is ndemo

 

Location/ndemo /{

 

Proxy_pass http: // localhost: 8088/ndemo /;

 

Include proxy. conf;

 

}

 

# Access the path under the root directory, webapp, to the ndemo project path by default, that is, to the above path

 

Location /{

 

Rewrite (. *) $/ndemo $1 permanent;

 

}

 

Location ~ ^/NginxStatus {# nginx status monitoring requires basic password protection, can be generated using apache tools, the way visible in http://www.blogjava.net/freeman1984/articles/363943.html}

 

Stub_status on;

 

Access_log off;

 

Auth_basic "valid-user ";

 

Auth_basic_user_file ewds_pw;

 

}

 

}

 

 

 

}

 

 

 

 

Proxy. conf:

 

 

 

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;

Www.2cto.com

Client_max_body_size 10 m;

 

Client_body_buffer_size 128 k;

 

Proxy_connect_timeout 300;

 

Proxy_send_timeouts 300;

 

Proxy_read_timeout 300;

 

Proxy_buffer_size 4 k;

 

Proxy_buffers 4 32 k;

 

Proxy_busy_buffers_size 64 k;

 

Proxy_temp_file_write_size 64 k;

 

 

 

 

Gzip. conf:

 

 

 

Gzip on;

 

Gzip_min_length 1024;

 

Gzip_types text/plain text/css application/x-javascript;

 

 

 

 

By the way, the comparison between tomcat and nginx and gzip is displayed. It is obvious that nginx is very efficient in processing static files.

 

Use tomcat separately:

 

Request status after nginx and gzip Compression

From crazy-Focus on java, open source, architecture, and Project Management

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.