Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。 其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页伺服器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯,另外知名的微网志Plurk也使用nginx。
1、整合Nginx与tomcat前提是相关环境已经安装成功;
2、执行cd /etc/nginx 命令切换目录,创建文件夹conf,如下:
[root@localhost nginx]# cd /etc/nginx [root@localhost nginx]# mkdir conf [root@localhost nginx]# ll total 44 drwxr-xr-x 2 root root 4096 Dec 22 20:15 conf
3、执行 cd conf 命令进入conf目录下,创建文件,如下:
[root@localhost nginx]# cd conf [root@localhost conf]# vim proxy.conf
增加以下内容,如下:
proxy_redirect off; proxy_set_headerHost $host; proxy_set_headerX-Real-IP $remote_addr; #获取真实IP #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #获取代理者的真实ip 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;
4、配置nginx.conf,文件在/etc/nginx目录下,配置文件修改为如下(简单配置,此配置已不会直接通过IP访问);
user www www; worker_processes 1; error_log /var/log/nginx/error.log warn; pid/var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf/proxy.conf; 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 /var/log/nginx/access.log main; sendfileon; #tcp_nopush on; keepalive_timeout 65; server { listen 80 default_server; server_name _; rewrite ^ http://www.yoodb.com$request_uri?; } server { listen 80; server_name www.yoodb.com; charset gb2312; location ~* /.bat { deny all; } location ^~ /configs/ { deny all; } location / { root /usr/local/apache-tomcat-7.0.56/webapps/ROOT; } location ~ .*$ { proxy_pass http://127.0.0.1:81; } location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ { expires 1m; } location ~ .*.(js|css)?$ { expires 1s; } } #gzip on; include /etc/nginx/conf.d/*.conf; }