nginx-my

#user nobody;
3 worker_processes 1;
4
5 error_log logs/error.log;
6 #error_log logs/error.log notice;
7 #error_log logs/error.log info;
8
9 #pid logs/nginx.pid;
10
11
12 events {
13 worker_connections 1024;
14 }
15
16 http {
17 include mime.types;
18 default_type application/octet-stream;
19
20 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
21 # '$status $body_bytes_sent "$http_referer" '
22 # '"$http_user_agent" "$http_x_forwarded_for"';
23
24 #access_log logs/access.log main;
25 large_client_header_buffers 4 16k;
26 client_max_body_size 300m;
27 client_body_buffer_size 128k;
28 proxy_connect_timeout 600;
29 proxy_read_timeout 600;
30 proxy_send_timeout 600;
31 proxy_buffer_size 256k;
32 proxy_buffers 4 256k;1
33 proxy_busy_buffers_size 256k;
34 proxy_temp_file_write_size 512k;
35 sendfile on;
36 #tcp_nopush on;
37  if ($host !~ ^(域名1|域名2)$ ) {

        return 444;

     }

38 #keepalive_timeout 0;

39 keepalive_timeout 65;
40 server_tokens off;
41
42 gzip on;
43 gzip_http_version 1.0;
44 gzip_min_length 1024;
45 gzip_comp_level 8;
46 gzip_disable "MSIE [1-6].";
47 gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php;
48
49 server {
50 listen 80;
51 server_name www.localhost localhost ;
52 #access_log logs/host.access.log main;
53 location / {
54 if ( $request_uri != /kft/onlinePay/callBack ) {
55 rewrite ^(.*)$ https://www.localhost$1 permanent;
56 }
57 proxy_pass http://localhost:8080/;

58 proxy_set_header Host $host;
59 proxy_set_header Port $proxy_port;
60 proxy_set_header XHost $host:$proxy_port;
61 proxy_set_header X-Real-IP $remote_addr;
62 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
63 #root html;
64 index index.html index.htm;
65 }
66 location ~ \.php$ {
67 root /wwwdata/tomcat7/webapps/ROOT;
68 fastcgi_pass 127.0.0.1:9000;
69 fastcgi_index index.php;
70 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
71 include fastcgi_params;
72 client_max_body_size 50m;
73 }
74 }
75
76 server {
77 listen 80;
78 server_name hb.localhost;
79 location / {
80 rewrite ^(.*)$ https://www.localhost/zt/money.html permanent;
81 }
82 }
83
84
85 server {
86 listen 443;
87 server_name www.localhost localhost ;
88 #access_log logs/host.access.log main;
89 ssl on;
90 ssl_certificate /wwwdata/nginx/SSL/66touzi.pem;
91 ssl_certificate_key /wwwdata/nginx/SSL/66touzi.key;
92 ssl_session_cache shared:SSL:10m;
93 ssl_session_timeout 10m;
94 ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
95 ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
96 ssl_prefer_server_ciphers on;
97 location / {
98 proxy_pass http://localhost:8080;
99 proxy_set_header Host $host;
100 proxy_set_header Port $proxy_port;
101 proxy_set_header XHost $host:$proxy_port;
102 proxy_set_header X-Real-IP $remote_addr;
103 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
104 # root html;
105 index index.jsp index.html index.htm;

106 if ( !-e $request_filename ) {
107 proxy_pass http://localhost:8080;   -------------------因为验证码为为动态验证图片(由js找到java,再在java添加时间标记),是虚拟url,由于代码的问题,必须写两段。
108 }
109 location ~ \.php$ {
110 root /wwwdata/tomcat7/webapps/ROOT;
111 fastcgi_pass 127.0.0.1:9000;
112 fastcgi_index index.php;
113 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
114 include fastcgi_params;
115 client_max_body_size 50m;
116 }
117 }

下面是静态由nginx处理,但有2个静态目录,一个匹配目录,一个用正则表达式,

118 location ^~ /zt/ {

119 root /wwwdata/tomcat7/webapps/ROOT;
120 expires 30d;
121 }
122 location ~ .*\.(gif|jpg|png|bmp|swf)$ #由nginx处理静态页面
123 {
124 root /wwwdata/tomcat7/webapps/ROOT/WEB-INF;
125 expires 30d; #使用expires缓存模块,缓存到客户
126 if ( !-e $request_filename ) {
127 proxy_pass http://localhost:8080;
128 }
129 }
130 location ~ .*\.(js|css)?$
131 {
132 root /wwwdata/tomcat7/webapps/ROOT/WEB-INF;
133 expires 1d;
134 }
135
136 }
137 }

posted on 2015-06-24 11:52  yang68h  阅读(240)  评论(0编辑  收藏  举报