一、下载地址
Nginx:http://nginx.org/en/download.html
Tomcat:http://tomcat.apache.org/
1、解压Nginx到:E:\server\nginx-1.2.9
命令行启动Nginx:
若果想停止nginx,dos环境运行命令:nginx -s stop
二、相关配置
2、Nginx配置:
Nginx配置文件默认在conf目录,主要配置文件为nginx.conf,我们安装在E:\server\nginx-1.2.9、默认主配置文件为E:\server\nginx-1.2.9\nginx.conf。下面是nginx作为前端反向代理服务器的配置。
Nginx.conf
View Code
#Nginx所用用户和组
#user niumd niumd;
#工作的子进程数量(通常等于CPU数量或者2倍于CPU)
worker_processes 2;
#错误日志存放路径
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
#指定pid存放文件
pid logs/nginx.pid;
events {
#使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue
#use epoll;
#允许最大连接数
worker_connections 2048;
}
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 off;
access_log logs/access.log;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 75 20;
include gzip.conf;
upstream localhost {
#ip_hash
#ip_hash;
server localhost:8080;
server localhost:8801;
}
server {
listen 80;
server_name localhost;
location / {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhost;
}
}
}
Proxy.conf
View Code
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 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
gzip on;
gzip_min_length 1000;
gzip_types text/plain text/css application/x-javascript;
Gzip.conf
View Code
gzip on;
gzip_min_length 1000;
gzip_types text/plain text/css application/x-javascript;
3、Tomcat配置
1)、因为我原先有Tomcat7,在D:\tomcat7
CATALINA_BASE:D:\tomcat7
CATALINA_HOME:D:\tomcat7
则这台Tomcat用端口8080访问;
2)、网上下载Tomcat,放:E:\server\apache-tomcat-7.0.53
CATALINA_BASE1:E:\server\apache-tomcat-7.0.53
CATALINA_HOME:E:\server\apache-tomcat-7.0.53
3)、修改新的tomcat中的startup.bat,把其中的CATALINA_HOME改为CATALINA_HOME1。
4)、修改新的tomcat中的catalina.bat,把其中的CATALINA_HOME改为CATALINA_HOME1
5)、修改conf/server.xml文件:
View Code
三、测试
1、启动两个Tomcat
2、启动Nginx:
我修改了index.jsp,现在访问localhost;
来源:oschina
链接:https://my.oschina.net/u/919503/blog/344029