开发者社区> 问答> 正文

nginx代理tomcat服务器,访问Nginx用Https,代理用http,但?报错

整体结构

用户--https-->Nginx--http-->Tomcat

页面中包含了iframe,iframe的src也是Https的,但是当frame里面的内容表单提交后tomcat服务器处理成功想要重定向却无法正常重定向,Chrome报错如下

Mixed Content: The page at 'https://...../#' was loaded over HTTPS, but requested an insecure form action 'http://.../**/**'. This request has been blocked; the content must be served over HTTPS.

我实在不知道怎么正确组织语言描述这个问题,不知道描述的大家能否理解,下面贴上Nginx的配置信息,希望大家抽时间帮忙看看,先谢过了

proxy.conf

proxy_redirect          off;
proxy_set_header        Host $host;
proxy_set_header        X-Real-IP $remote_addr;  #获取真实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;

defalut

server {
listen 80 default_server;

server_name localhost;

return 301 https://$server_name:6663$request_uri;
}

server {
listen 6663;

server_name localhost;

ssl     on;
ssl_certificate      /home/dream/Https/ssl/server/server.crt;
ssl_certificate_key  /home/dream/Https/ssl/server/server.pem;
ssl_client_certificate /home/dream/Https/ssl/server/root.crt;
 
ssl_session_timeout  5m;
ssl_verify_client on;  #开户客户端证书验证

ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://127.0.0.1:8080/;
}
}

系统环境:

nginx version: nginx/1.4.6 (Ubuntu)  built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)

Ubuntu 14.04

Chrome版本 42.0.2311.135 (64-bit)

展开
收起
爱吃鱼的程序员 2020-06-14 16:17:40 1204 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    这是因为tomcat重定向的时候给你变成http了。

    加个  proxy_redirect试试

    proxy_passhttp://127.0.0.1:8080/;

    proxy_redirect~^http://([^:]+)(:\d+)?(.*)$ https://$1$3;

    实测可以解决,谢谢大佬~ 用户-->https-->Nginx--> https-->Tomcat springmvc<- < property   name = "redirectHttp10Compatible"   value = "false"   />   这句可以解决 ->

    <!--定义视图文件解析-->

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

    <property name="prefix" value="${web.view.prefix}"/>

    <property name="suffix" value="${web.view.suffix}"/>

    <property name="redirectHttp10Compatible" value="false" /> 

    </bean>

    解决了?

    引用来自“FeiFeiZheng”的评论

    这是因为tomcat重定向的时候给你变成http了。

    加个  proxy_redirect试试

    proxy_passhttp://127.0.0.1:8080/;

    proxy_redirect~^http://([^:]+)(:\d+)?(.*)$ https://$1$3;

    2020-06-14 16:17:58
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载