首页 新闻 会员 周边

使用nginx反向代理网站时 , 网站加载报错

0
[已解决问题] 解决于 2021-10-08 16:40

反向代理成功后 , 网站可以进去 , 但是初始化加载时报错 , 执行ajax请求时报错 , nginx配置如下 :
server {
listen 8010;
server_name 192.168.2.105;

    #location / {
    #    root   html;
    #    index  index.html index.htm;
    #}
    
    location / {
        proxy_pass http://192.168.2.105:820;
        proxy_redirect default;
        proxy_set_header Host  $http_host;
        proxy_set_header Cookie $http_cookie;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        add_header 'Access-Control-Allow-Origin' '*';  
        add_header 'Access-Control-Allow-Credentials' 'true';  
        client_max_body_size  100m;
        proxy_connect_timeout       1;
    }

    location /TianChen/ {
        rewrite  ^.+TianChen/?(.*)$ /$1 break; 
        include  uwsgi_params;
        proxy_pass http://192.168.2.143:808/;
        proxy_set_header Host  $http_host;
        proxy_set_header Cookie $http_cookie;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        add_header 'Access-Control-Allow-Origin' '*';  
        add_header 'Access-Control-Allow-Credentials' 'true';  
        client_max_body_size  100m;
        proxy_connect_timeout       1;
    }
    
    location ~.*\.(html|js|css|map|gif|png|jpg|woff|woff2|ico)$ {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header Access-Control-Allow-Origin $http_origin;
        add_header Access-Control-Allow-Headers X-Requested-With;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        proxy_pass http://192.168.2.143:808;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        sub_filter <head> '<head> <meta name="referrer" content="no-referrer" />';
    }

报错图 :

救赎之旅-的主页 救赎之旅- | 初学一级 | 园豆:94
提问于:2021-09-22 13:17
< >
分享
最佳答案
0

rootpath是什么

奖励园豆:5
顾晓北 | 专家六级 |园豆:10844 | 2021-09-22 13:54

获取的当前的网址, 所以地址不对,现在是2.105:8010 应该为1.143:808才对
这个能配置代理转发之类的吗

救赎之旅- | 园豆:94 (初学一级) | 2021-09-22 13:57

现在是把1.143:808的系统在nginx上做了一个代理,用户通过1.105:8010访问

救赎之旅- | 园豆:94 (初学一级) | 2021-09-22 13:58

@救赎之旅-: 你这个配置,应该是访问8010,实际转发到808和820吧?

顾晓北 | 园豆:10844 (专家六级) | 2021-09-22 14:06

@救赎之旅-: 这是你想要的?你rootpath()得到的是什么?

顾晓北 | 园豆:10844 (专家六级) | 2021-09-22 14:07
其他回答(1)
0

你应该是访问 http(s)://your nginx ip:port/your context-path

去哪里吃鱼 | 园豆:462 (菜鸟二级) | 2021-09-22 14:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册