user nginx nginx;
worker_processes 4;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 65535;
events {
worker_connections 65535;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log logs/access.log main;
log_format cache ‘***$time_local ‘ ‘***$upstream_cache_status ‘ ‘***Cache-Control: $upstream_http_cache_control ‘
‘***Expires: $upstream_http_expires ‘ ‘***"$request" ($status) ‘ ‘***"$http_user_agent" ‘;
access_log logs/cache_access.log cache;
client_max_body_size 200m;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
client_header_timeout 10;
client_body_timeout 10;
send_timeout 10;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/palin application/x-javascript text/css application/xml;
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
proxy_ignore_client_abort on;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /home/temp_dir;
proxy_cache_path /home/cache levels=1:2 keys_zone=cache_one:1024m inactive=1d max_size=10g;
upstream company {
server 192.168.3.5:8080 ;
server 192.168.3.5:9080 ;
# jvm_route $cookie_JSESSIONID|sessionid reverse;
ip_hash;
}
include /usr/local/nginx/conf/vhost/*.conf;
}
虚拟主机的配置文件
server {
listen 80;
server_name img.sxlfxx.cn;
root /webfile/images;
charset utf-8;
# location / {
# proxy_pass http://company;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $remote_addr;
# }
location ~* .*\.(bmp|img|jpeg|jpg|png|gif|svg|png|ico|txt|css|js|html|htm|pdf|apk)$ {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_valid 301 302 1m;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Accept-Encoding ‘‘;
proxy_ignore_headers "Cache-Control" "Expires";
add_header X-Cache "Hit from ngnix.com";
expires 7d;
}
location ~ .*\.(do|jsp)$ {
proxy_pass http://company;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_ignore_headers "Cache-Control" "Expires";
add_header X-Cache "Miss from ngnix.com";
}
location /status {
stub_status on;
access_log /usr/local/nginx/logs/status.log;
auth_basic "NginxStatus";
}
}
后端tomcat的虚拟主机配置
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost" jamRoute="tomcat1">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="a.sxlfxx.cn" appBase="/webfile"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="sxlfxx-a-web" debug="0" reloadable="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="b.sxlfxx.cn" appBase="/webfile"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="sxlfxx-b-web" debug="0" reloadable="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="c.sxlfxx.cn" appBase="/webfile"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="sxlfxx-c-web" debug="0" reloadable="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="www.sxlfxx.cn" appBase="/webfile"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="sxlfxx-www-web" debug="0" reloadable="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
</Host>
</Engine>
</Service>
</Server>
本文出自 “→おyǒňɡ無祉境℃” 博客,转载请与作者联系!
原文:http://sxlfxx.blog.51cto.com/4244111/1707415