Laravel使用服务器IP加载文件和链接URL,而不是访问请求的URL

我的Laravel网站托管在我重定向URL的IP上。 问题是索引页面加载但是所有的css,js和图像都是从IP而不是URL加载的。 即使所有内部链接都要转到那个IP。

是laravel仅基于主机IP创建URL,而不是将请求URL转换为帐户。</ p>

例如:假设我的网站主机IP是1.2.3.4/xyz,我访问它的URL是 sub.abc.com/xyz
Then如果我加载sub.abc.com/xyz页面打开,但js css和图像来自1.2.3.4/xyz而不是sub.abc.com/xyz
链接将转到 1.2.3.4/xyz/contact而不是abc.com/xyz/contact


nn

我使用laravel的方法制作这些URL </ p>

注意:xyz 文件夹被代理转移到另一个IP </ p>
</ div>

展开原文

原文

My Laravel site is hosted on a IP to which I am redirecting a URL. The problem is that index page loads but all the css, js and images are being loaded from the IP and not the URL. Even all the internal links are going to that IP. Is laravel creating URLS based only on host IP instead of taking Request URL into acount.

Eg: Suppose my host IP for website is 1.2.3.4/xyz and my URL to access it is sub.abc.com/xyz Then If I load sub.abc.com/xyz page opens but the js css and images are coming from 1.2.3.4/xyz instead of sub.abc.com/xyz And links are going to 1.2.3.4/xyz/contact instead of abc.com/xyz/contact

I am using laravel's methods to make these URLs

Note: xyz folder is being proxypassed to another ip

duanjiu1894
duanjiu1894 是的,我做了所有这些,但那不是问题
6 年多之前 回复
duanlei2458
duanlei2458 您是否尝试在bootstrap/start.php$app->detectEnvironment调用中更改“主机名”?
6 年多之前 回复

2个回答



Ok Laravel IRC聊天我知道这个问题与服务器配置有关。 </ p>

思考所有配置我想这就是发生的事情并导致问题</ p>

我们输入sub.abc.com/xyz应该转到abc .com - &gt; sub - &gt; xyz文件夹
现在请求URL是sub.abc.com/xyz


nnn

但是在这个文件夹中没有网站文件而是请求( 代理通过)到另一个位置1.2.3.4/xyz,它应该在1.2.3.4上查找文件夹xyz所以现在请求URL变成1.2.3.4/xyz


nnn

所以当它到来时 在1.2.3.4/xyz的Laravel,请求URL是1.2.3.4/xyz而不是sub.abc.com/xyz所以laravel的所有文件和链接都返回,URL为1.2.3.4/xyz </ p>

因此,现在访问浏览器的页面有1.2.3.4/xyz链接,而不是请求sub.abc.com/xyz
你可能会说,如果我说的是真的那么为什么不域名和 所有网站都有相应的IP中断。</ p>

我会说的是</ p>

让我们输入xyz.com,它指向4.5.6.7 IP。

再次网站获取请求URL为4.5.6.7并在同一链接发送文件
然后再次将此IP 4.5.6.7映射回xyz.com并提供给浏览器,以便brwser获得正确的链接。</ p>
</ DIV>

展开原文

原文

Ok from Laravel IRC chat I got to know that problem is something with the server configuration.

Thinking over all the configuration I guess this is what happening and causing problem

We type sub.abc.com/xyz which should go to abc.com-->sub-->xyz folder So now Request URL is sub.abc.com/xyz

But in this folder there are no website files instead a Request(proxypassed) is made to another location 1.2.3.4/xyz which should look for a folder xyz on 1.2.3.4 So now the Request URL becomes 1.2.3.4/xyz

So now when it comes to Laravel at 1.2.3.4/xyz, the Request URL is 1.2.3.4/xyz and not sub.abc.com/xyz so all the files and links from laravel are returned with a URL of 1.2.3.4/xyz

Hence now the page that comes to the browser has 1.2.3.4/xyz links instead of requested sub.abc.com/xyz Now you may say that if whatever I said is true then why dont domain and corresponding IP breaks in all websites.

For which I will say that

Lets say you type xyz.com which points to 4.5.6.7 IP. here again website gets request URL as 4.5.6.7 and sends the file at same link But then again this IP 4.5.6.7 is mapped back to xyz.com and served to browser so brwser gets correct link.



使用Apache虚拟主机ProxyPass指令添加 ProxyPreserveHost On </ code>。</ p>
</ div>

展开原文

原文

Add ProxyPreserveHost On with your Apache virtual host ProxyPass directives.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问