【发布时间】:2019-11-27 12:56:29
【问题描述】:
我在 VPS 上设置了一个 nginx 服务器,并尝试基于此设置制作网站。我遇到的问题是访问php页面时似乎无法加载外部js文件(存储在服务器中)。
这是我的 nginx.conf,server_name 和 root 的名称出于隐私原因已更改:
server {
listen 80;
server_name example.com;
root /var/www/example;
index index.html index.htm index.php;
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ \.(js|jpg|png|css)(.*)$ {
expires 30d;
}
}
这是我的 php 测试页面
<!doctype html>
<html lang="en">
<head>
<!-- update aob -->
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script scr="example.js"></script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>test page</title>
</head>
<body>
<script>
console.log("hello");
</script>
</body>
</html>
这是我的 javascript,example.js,它位于 php 文件的同一根目录:
console.log('print something');
当我访问 example.php 时,我希望看到控制台将显示: 打印一些东西 你好
但是当我访问该页面时,我只执行了内联脚本。我用了chrome的inspector,发现js文件根本没有加载,但是其他CDN提供的脚本都可以正常加载。
我试图为此找到解决方案,我怀疑我的 nginx.conf 有问题,但我找不到任何可以解决我的问题的方法。请帮忙。
【问题讨论】:
-
仔细观察。
scr!=src. -
@esqew 敏锐观察!
-
@esqew 我觉得自己很愚蠢,哈哈,非常感谢你,伙计!
标签: javascript php nginx