我php -S localhost:8000
用作我的开发服务器。最后,我将使用nginx。但是我对php服务器有问题。
root
|
|---/app
|
|---/index.html
|---/scripts
| |
| |---/main.css
|
|---/styles
|
|---/main.js
在我的app/index.html
我有:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles/main.css" type="text/css" />
</head>
<body>
<script src="scripts/main.js"></script>
</body>
</html>
当我使用localhost:8000/app
CSS和浏览器在浏览器中打开页面时,找不到javascript。浏览器正在寻找localhost:8000/styles
响应。localhost:8000/scripts
而不是localhost:8000/app/styles
分别。localhost:8000/app/scripts
。当我不使用服务器或使用nginx直接打开文件时,可以正确找到文件。所以PHP服务器改变了一些东西。这里发生了什么?
我在Chrome和Firefox中尝试过。两种浏览器中的行为相同。当我用localhost/app
(nginx
)打开网站时,一切正常。当我使用localhost:8000/app
(php -S localhost:8000
)打开网站时,找不到脚本和样式。这是具有相同文件根的相同文件。不同的行为从何而来?
在检查了PHP:内置Web服务器上的官方文档后,它明确指出:
URI请求是从启动PHP的当前工作目录提供的,除非使用-t选项指定显式文档的根目录。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句