Windows下Nginx+Tomcat整合的安装与配置
来源:互联网 发布:linux创建新用户并授权 编辑:程序博客网 时间:2024/05/16 02:41
反向代理(Reverse Proxy): 方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个服务器
安装nginx
Nginx官网地址:http://nginx.org/en/download.html
1.找到你解压的路径,执行nginx.exe,也许你会看到窗口一闪而过,其实是成功了,此时打开任务管理器,会看到
第二种启动方案 进入cmd ,找到你解压的路径,执行start nginx
关闭nginx: 进入cmd,执行nginx -s stop
ningx文件夹里面有一个conf文件夹,讨论nginx.conf文件
include gzip.conf;upstream localhost {
server localhost:8080;
server localhost:8801;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost;
}
}
执行http://localhost
有可能这样访问的时候会非常慢,网上有两种方案:
第一种方案:修改
location / {
proxy_pass http://localhost_server1;
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 1;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
root html;
index index.html index.htm;
}
第二种方案:把 upstream localhost {
server localhost:8080;
server localhost:8801;
}
修改为
upstream localhost {
server 127.0.0.1:8080;
server 127.0.0.1:8801;
}
---原因未知----
nginx详解
#Nginx用户及组:用户 组。window下不指定
#user nobody;
#工作进程:数目。根据硬件调整,通常等于CPU数量或者2倍于CPU。
worker_processes 1;
#错误日志:存放路径。
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid(进程标识符):存放路径。
#pid logs/nginx.pid;
#指定进程可以打开的最大描述符:数目。
#这个指令是指当一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(ulimit -n)与nginx进程数相除,但是nginx分配请求并不是#那么均匀,所以最好与ulimit -n 的值保持一致。
#现在在linux 2.6内核下开启文件打开数为65535,worker_rlimit_nofile就相应应该填写65535。
#这是因为nginx调度时分配请求到进程并不是那么的均衡,所以假如填写10240,总并发量达到3-4万时就有进程可能超过10240了,这时会返回502错误。
#worker_rlimit_nofile 204800;
events {
#使用epoll的I/O 模型。linux建议epoll,FreeBSD建议采用kqueue,window下不指定。
#补充说明:
#与apache相类,nginx针对不同的操作系统,有不同的事件模型
#A)标准事件模型
#Select、poll属于标准事件模型,如果当前系统不存在更有效的方法,nginx会选择select或poll
#B)高效事件模型
#Kqueue:使用于FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 和 MacOS X.使用双处理器的MacOS X系统使用kqueue可能会造成内核崩溃。
#Epoll:使用于Linux内核2.6版本及以后的系统。
#/dev/poll:使用于Solaris 7 11/99+,HP/UX 11.22+ (eventport),IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+。
#Eventport:使用于Solaris 10。 为了防止出现内核崩溃的问题, 有必要安装安全补丁。
#use epoll;
#没个工作进程的最大连接数量。根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行。每个进程允许的最多连接数,理论上每#台nginx服务器的最大连接数为。worker_processes*worker_connections
worker_connections 1024;
keepalive_timeout 60;
#keepalive超时时间。
client_header_buffer_size 4k;
#客户端请求头部的缓冲区大小。这个可以根据你的系统分页大小来设置,一般一个请求头的大小不会超过1k,不过由于一般系统分页都要大于1k,所以这#里设置为分页大小。
#分页大小可以用命令getconf PAGESIZE 取得。
#4096
#但也有client_header_buffer_size超过4k的情况,但是client_header_buffer_size该值必须设置为“系统分页大小”的整倍数。
open_file_cache max=65535 inactive=60s;
#这个将为打开文件指定缓存,默认是没有启用的,max指定缓存数量,建议和打开文件数一致,inactive是指经过多长时间文件没被请求后删除缓存。
open_file_cache_valid 80s;
#这个是指多长时间检查一次缓存的有效信息。
open_file_cache_min_uses 1;
#open_file_cache指令中的inactive参数时间内文件的最少使用次数,如果超过这个数字,文件描述符一直是在缓存中打开的,如上例,如果有一个文件在#inactive时间内一次没被使用,它将被移除。
}
http {
#设定mime类型,类型由mime.type文件定义
include mime.types;
default_type application/octet-stream;
#日志格式设置。
#通常web服务器放在反向代理的后面,这样就不能获取到客户的IP地址了,通过$remote_add拿到的IP地址是反向代理服务器的iP地址。反向代理服务器在#转发请求的http头信息中,可以增加x_forwarded_for信息,用以记录原有客户端的IP地址和原来客户端的请求的服务器地址。
#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;
#nginx的upstream目前支持4种方式的分配
#1.轮询(默认) 2.weight 3.ip_hash 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决#session的问题。
upstream localhost_server1 {
#ip_hash
server 127.0.0.1:8090 weight=3;
server 127.0.0.1:8070 weight=2;
}
server {
listen 8010;
#配置访问域名
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#每个设备的状态设置为:
#1.down表示单前的server暂时不参与负载
#2.weight为weight越大,负载的权重就越大。
#3.max_fails:允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream模块定义的错误
#4.fail_timeout:max_fails次失败后,暂停的时间。
#5.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
#nginx支持同时设置多组的负载均衡,用来给不用的server来使用。
#client_body_in_file_only设置为On 可以讲client post过来的数据记录到文件中用来做debug
#client_body_temp_path设置记录文件的目录 可以设置最多3层目录
#location对URL进行匹配.可以进行重定向或者进行新的代理 负载均衡
proxy_pass http://localhost_server1;
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 1;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
root html;
index index.html index.htm;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
- Windows下Nginx+Tomcat整合的安装与配置
- windows下Nginx+Tomcat整合的安装与配置 .
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置
- Windows下Nginx+Tomcat整合的安装与配置(一)
- Windows下Nginx+Tomcat整合的安装与配置(一)【精】
- mint-ui loadmore 上拉加载的坑
- Java8基础_Hashmap
- Angular之基础知识
- FFMpeg无损合并视频的多种方法
- 国密算法概述
- Windows下Nginx+Tomcat整合的安装与配置
- Eclipse如何自动补全的设置
- android Inspector View Hierarchy
- php日期时间处理date() strtotime() mktime()
- 数据表的基本操作 例题 stage1-6
- 理解jquery的$.extend()、$.fn和$.fn.extend()
- 使用IndicatorFragmentActivity添加子级Fragment时,在Activity中获取子级的方法
- JVM运行时数据区域分配
- Csipsimple Pjsip底层注册的实现(附Demo)