# Top-level configuration information Management Server-level behavior Worker_processes 1;# event instruction is related to events model, configuring processing connection information Events {worker_connections 1024;} # HTTP instruction handles HTTP request HTTP {# MIME type mapping include mime.types; Default_type Application/octet-stream; Sendfile on; #tcp_nopush on; #keepalive_timeout 0; Keepalive_timeout 65; #gzip on;# Server represents a virtual host, one server can configure multiple virtual host server {# Listening ports listen 80;# recognized domain name server_name localhost; # A key setting, with URL parameter garbled problem about CharSet utf-8; #access_log Logs/host.access.log main; #location表达式: #syntax: Location [=|~|~*|^~|@]/uri/{...} #分为两种匹配模式, normal string match, regular match # No start-up guide character or = begins with = Normal string Match # begins with ~ or ~* to indicate a regular match, ~* indicates a case-insensitive # multiple location Match Rule # The general is the first normal after the regular principle, only the URI part is recognized, For example, the request is/test/1/abc.do?arg=xxx#1. Find out if there is an exact match at the beginning = location =/test/1/abc.do {...} #2. Then find the normal match, with the maximum prefix as the rule, such as the following two location# location/test/{...} # location/test/1/{...} # then match the last one. After matching to a normal format, the search does not end, but the current results are staged, and the regular mode # # is continued to be searched. After the first match is found in all regular mode location, the match is the final result # so the regular match match rule is affected by the defined order, but the normal match does not. If a regular match is not found, the cache in 3The result is the final result, the. If there is no match, return 404#location =/{...} difference from location/{...} before one is exact match, only response/request, All/XXX class requests do not match the prefix match form to it # then the other is the opposite, and all the requests must start with/ So no other match results will be executed to it #location ^~/{...} ^~ means non-regular, means no longer regular search after matching to this pattern # All if this is configured, it is equivalent to turning off the regular match function # because a request does not have other common matching results under the normal match rule , and the final match here # and this ^~ instruction is equivalent to not allow the regular, equivalent to the end of the location/{root HTML; Index index.html index.htm;# deny all; Deny request, return 403# allow all; Allow request}location/test/{deny all;} Location ~/test/.+\.jsp$ {Proxy_pass http://192.168.1.62:8080;} Location ~ \.jsp$ {Proxy_pass http://192.168.1.61:8080;} # define various error pages error_page 404/404.html; # REDIRECT Server error pages to the static page/50x.html # Error_page 502 503 504/50x.html; Location =/50x.html {root html; }# @ is similar to variable definition # error_page 403 http://www.cnblogs.com/zyw-205520/This definition is not allowed, so use @ To achieve Error_page 403 @page403; Location @ page403 {Proxy_pass http://www.cnblogs.com/zyw-205520/;} } # Another virtual HOST using mix of ip-, name-, and port-based configuration server {listen; #listen 9090 serve R_name www.test.com test.com other.cc; Location/{# root d:\\test; Note that win under D:\test because of escape character problem does not allow root d:/test index index.html index.htm; } }}
Nginx Configuration Detailed