duandaiqin6080 2013-06-19 09:57
浏览 607

如何从nginx重定向到另一个Web服务器

i have tried to redirect to php and node.js from nginx. this is my nginx code

server {

       listen 8060;
       server_name mydomain;
       access_log /var/log/nginx/mydomain.log;
       location /
       {
            proxy_pass http://mydomain;
       }
       location /node {

       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $http_host;
       proxy_set_header X-NginX-Proxy true;
       proxy_pass http://mydomain/;
       proxy_redirect off;
      }
   }

when i run localhost:8060 in browser it is redirecting to localhost:70. from here added /index.html in browser it is showing that html page.i have written on ajax call within that html page. so when i click submit button ajax will be called and then send request to php and getting response from php within success function of ajax.it is working fine.and then again i am redirecting to nginx from that success function itself this is that code

               $.ajax(
                    {
                    url:"service/lpage.php",
                    type:"GET",
                    contentType: "application/json",   
                    dataType:'json',
                    data:{"uname":user,"password":pass},
                    success:function(data)
                    {
                            if(data.token)
                            {

                                    window.location="http://mydomain:8060/node?token="+data.token;
                            }
                    },
                     error: function(data,statusCode) { 
                    alert('Error ' + statusCode); 
                    } 
            });

again i am redirecting to node.js from nginx by using this proxy_pass 127.0.0.1:4000/; yes it is redirect but when it is redirecting to node.js i am rendering one html .so js and css files are in localhost:4000 but it is seeking that library 127.0.0.1:8060 so i am getting Not found error in my firebug.how to resolve this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?