当前位置:   article > 正文

使用nginx反向代理tomcat服务,走https经常自动跳转到http 解决方案_nginx代理怎么避免跳转

nginx代理怎么避免跳转

使用nginx反向代理tomcat服务,走https经常自动跳转到http,遇到此种问题,我们需要做两方面设置:

1. nginx中配置

在nginx中 要配置 proxy_set_header X-Forwarded-Proto $scheme;

如下所示:

nginx.conf 文件

  1. location ^~ /infomation/ {
  2. proxy_redirect off;
  3. proxy_set_header Host $host;
  4. proxy_set_header X-Real-IP $remote_addr;
  5. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  6. proxy_set_header X-Forwarded-Proto $scheme;
  7. proxy_pass http://serverInformation;
  8. }

upstream.conf文件

  1. upstream serverInformation {
  2. server 192.168.0.150:10100;
  3. }

2. tomcat中配置

在tomcat server.xml中做如下配置

  1. <Connector port="10100" protocol="HTTP/1.1"
  2. connectionTimeout="20000" minSpareTHreads="30"
  3. redirectPort="8443" URIEncoding="utf-8" />

  1. <Engine name="Catalina" defaultHost="localhost">
  2. <!--For clustering, please take a look at documentation at:
  3. /docs/cluster-howto.html (simple how to)
  4. /docs/config/cluster.html (reference documentation) -->
  5. <!--
  6. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  7. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  8. via a brute-force attack -->
  9. <Realm className="org.apache.catalina.realm.LockOutRealm">
  10. <!-- This Realm uses the UserDatabase configured in the global JNDI
  11. resources under the key "UserDatabase". Any edits
  12. that are performed against this UserDatabase are immediately
  13. available for use by the Realm. -->
  14. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  15. resourceName="UserDatabase"/>
  16. </Realm>
  17. <Host name="localhost" appBase="webapps"
  18. unpackWARs="true" autoDeploy="true">
  19. <!-- SingleSignOn valve, share authentication between web applications
  20. Documentation at: /docs/config/valve.html -->
  21. <!--
  22. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  23. -->
  24. <!-- Access log processes all example.
  25. Documentation at: /docs/config/valve.html
  26. Note: The pattern used is equivalent to using pattern="common" -->
  27. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  28. prefix="localhost_access_log." suffix=".txt"
  29. pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  30. <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https"/>
  31. </Host>
  32. </Engine>
  33. </Service>
  34. </Server>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/592931
推荐阅读
相关标签
  

闽ICP备14008679号