Nginx配置总结
2015-09-07 18:33
671 查看
修改nginx服务器配置,在conf文件下的nginx.conf文件。
常见问题总结:
1. nginx+tomcat影响request值
request.getScheme() //总是 http,而不是实际的http或https
request.isSecure() //总是false(因为总是http)
request.getRemoteAddr() //总是 nginx 请求的 IP,而不是用户的IP
request.getRequestURL() //总是 nginx 请求的URL 而不是用户实际请求的 URL
request.getServerName //总是nginx请求的ip
request.getServerPort //总是nginx请求的端口
response.sendRedirect( 相对url ) //总是重定向到 http 上 (因为认为当前是 http 请求)
解决方法:
修改nginx配置:
配置tomcat的server.xml的Engine模块,配置一个value
#user nobody; #运行用户 #worker_processes 1; #启动进程数,通常设置成和cpu数目相同 #error_log /var/log; #错误日志 events { worker_connections 1024;#单个后台work process进程最大并发链接数 } #设定http服务器 http{ #设定mime类型,类型由mime.type文件定义 include /etc/nginx/mime.types; default_type application/octet-stream; #设定日志格式 access_log /var/log/nginx/access.log; sendfile on; #连接超时时间 #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; #集群中的所有后台服务器的配置信息,用于负载均衡 upstream local_tomcat{ server 192.168.0.111:80; server 192.168.0.109:8080; } server{ listen 8090; #当前代理服务器监听端口 server_name localhost:80; #监听后要转到地址 #charset koi8-r; #access_log logs/host.access.log main; location / { #location表示匹配路径,/表示所有请求 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; } } }
常见问题总结:
1. nginx+tomcat影响request值
request.getScheme() //总是 http,而不是实际的http或https
request.isSecure() //总是false(因为总是http)
request.getRemoteAddr() //总是 nginx 请求的 IP,而不是用户的IP
request.getRequestURL() //总是 nginx 请求的URL 而不是用户实际请求的 URL
request.getServerName //总是nginx请求的ip
request.getServerPort //总是nginx请求的端口
response.sendRedirect( 相对url ) //总是重定向到 http 上 (因为认为当前是 http 请求)
解决方法:
修改nginx配置:
proxy_set_header Host $host; #解决getRequestURL、getServerName、getServerPort问题 proxy_set_header X-Real-IP $remote_addr;#把真实的ip发送给转发的web服务器 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#解决request.getScheme()只能返回http而不是https问题
配置tomcat的server.xml的Engine模块,配置一个value
< Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https" />
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- 网站502与504错误分析
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- web 应用中常用的各种 cache详解
- Linux系统上配置Nginx+Ruby on Rails+MySQL超攻略
- window+nginx+php环境配置 附配置搭配说明
- 解析CI即CodeIgniter框架在Nginx下的重写规则
- 将PHP从5.3.28升级到5.3.29时Nginx出现502错误
- 基于Nginx0.8.54+PHP5.3.4+MySQL5.5.8的全新LNMP稳定版架构搭建的VPS
- Nginx(PHP/fastcgi)的PATH_INFO问题
- 如何让Nginx支持中文文件名具体设置步骤
- Nginx upstream的5种权重分配方式分享
- 分析nginx日志并屏蔽采集者ip(nginx屏蔽ip配置实例)