nginx和tomcat做整合,nginx代理访问tomcat页面,一级页面能访问,但是二级页面提示404错误。

#user  nobody;
user www www;
worker_processes  8;

error_log  /usr/local/nginx/logs/error.log crit;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /usr/local/nginx/nginx.pid;

worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections  65535;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
#    include /usr/local/nginx/conf/proxy.conf;
    charset utf-8;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 300m;
    #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;

    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  60;
    tcp_nodelay on;
    client_body_buffer_size 512k;
    proxy_connect_timeout 5;
    proxy_read_timeout 60;
    proxy_send_timeout 5;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    
    upstream tomcat_server {
    server 192.168.0.3:8080;

}

    #gzip  on;

    server {
        listen       80;
        server_name  192.168.0.3;
	index index.html index.htm index.jsp index.do default.do;
	root /home/www;
	if (-d $request_filename)
{
	rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
	
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location ~ \.(jsp|jspx|do)?$ {
        proxy_set_header Host $host;
	proxy_set_header X-Forwarded-For $remote_addr;
	proxy_pass http://tomcat_server;
}    
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
	expires 30d;
}
location ~ .*\.(js|css)?$
{
	expires 1h;
}
access_log off;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
2011-08-23 16:40 提问者采纳
user  nobody;
worker_processes  2;

error_log	logs/error.log;
#error_log	logs/error.log  notice;
#error_log	logs/error.log  info;

pid	logs/nginx.pid;

events {
	worker_connections	1024;
}

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;

	sendfile	on;
	#tcp_nopush	on;

	#keepalive_timeout	0;
	keepalive_timeout	65;

	gzip	on;

	upstream tomcat_server {
		server 192.168.130.128:8080 weight=5;
		server 192.168.130.129:8080 weight=5;
		ip_hash;
	}

	server {
		listen       80;
		server_name  localhost;

		charset utf-8;

		access_log  logs/host.access.log  main;

		location / {
			proxy_pass http://tomcat_server;
			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;
           		client_max_body_size	10m;
           		client_body_buffer_size	128k;
           		proxy_connect_timeout	90;
           		proxy_send_timeout	90;
           		proxy_read_timeout	90;
           		proxy_buffer_size	4k;
           		proxy_buffers	4 32k;
           		proxy_busy_buffers_size	64k;
           		proxy_temp_file_write_size	64k;
		}

error_page  404              /404.html;

        	error_page   500 502 503 504  /50x.html;
        	location = /50x.html {
            		root   html;
		}
        }
}

你可能感兴趣的:(nginx)