nginx加载静态资源出错

CodePrayer 发布于 03/03 17:50
阅读 581
收藏 1

配置完nginx虚拟主机后,如果用 http://localhost/ 登录可以正常显示页面

但使用自己配置的域名www.xuecheng.com登录就出现问题

下面是nginx的配置:

    server {
        listen       80;
        server_name  www.xuecheng.com;
	ssi on;
	ssi_silent_errors on;
        location  /  {
            alias   E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/;
            index  index.html;
        }

    }

日志记录的错误:用http://localhost/和www.xuecheng.com登录出现的错误是相同的

2020/03/03 17:33:48 [error] 2592#3304: *78 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/plugins/normalize-css/normalize.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/plugins/normalize-css/normalize.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2020/03/03 17:33:48 [error] 2592#3304: *79 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/plugins/bootstrap/dist/css/bootstrap.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/plugins/bootstrap/dist/css/bootstrap.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2020/03/03 17:33:48 [error] 2592#3304: *78 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/css/page-learing-article.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/css/page-learing-article.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2020/03/03 17:33:48 [error] 2592#3304: *79 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/css/page-learing-index.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/css/page-learing-index.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2020/03/03 17:33:48 [error] 2592#3304: *78 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/img/asset-logoIco.png" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/img/asset-logoIco.png HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2020/03/03 17:33:48 [error] 2592#3304: *78 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/plugins/bootstrap/dist/css/bootstrap.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/plugins/bootstrap/dist/css/bootstrap.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2020/03/03 17:33:48 [error] 2592#3304: *78 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/css/page-learing-article.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/css/page-learing-article.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2020/03/03 17:33:48 [error] 2592#3304: *78 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/plugins/normalize-css/normalize.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/plugins/normalize-css/normalize.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2020/03/03 17:33:48 [error] 2592#3304: *78 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/plugins/bootstrap/dist/css/bootstrap.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/plugins/bootstrap/dist/css/bootstrap.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2020/03/03 17:33:48 [error] 2592#3304: *78 CreateFile() "E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/css/page-learing-index.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: www.xuecheng.com, request: "GET /static/css/page-learing-index.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"

有大神能够解答一波吗?感谢~(已纠缠n小时未解决的问题)

加载中
0
大盘
大盘

E:/xcEdu/xcEduUI01/xc-ui-pc-static-portal/static/plugins/normalize-css/normalize.css

有这些文件吗???

CodePrayer
CodePrayer
有,但是路径中自动加了static,所以报错找不到。但是localhost登录的时候页面没什么问题
0
慢慢成长
慢慢成长

www.xuecheng.com 配一下host

CodePrayer
CodePrayer
加了 127.0.0.1 www.xuecheng.com
0
ops-coffee
ops-coffee

先把alias换成root

CodePrayer
CodePrayer
额,没用
0
CodePrayer
CodePrayer

不明白为什么localhost可以,但是用配置好的域名却不行。。。明明在host里也配置了呀,而且。。还把localhost配置的那个给注释掉了也没用。。。

#127.0.0.1       localhost
#	::1             localhost
#127.0.0.1  www.xmind.net
#127.0.0.1       activate.navicat.com 
127.0.0.1 www.xuecheng.com 

 

白菜粉条炖猪蹄儿
实在不行你就再在nginx里面配置一个server,里面用proxy_pass到localhost。不过问题应该不是这样处理的,还是研究下,去看下代码里面的路径。
0
Yongy
Yongy

遇到这种请求访问不正确的问题。先把请求地址换成绝对路径,检查是否能访问到资源文件

 

 
Yongy
Yongy
这是放到服务器上了,还是本地通过代理域名访问的。 这两个可不一样
CodePrayer
CodePrayer
试过直接访问绝对路径来访问资源文件,localhost可以,但是自定义的域名不可以
0
d
dongjw321

看下NGINX里面的配置,是不是目录,加一个目录试下,在fastcgi.conf 里面

fastcgi_param PHP_ADMIN_VALUE "open_basedir=/data/wwwroot:$document_root/:/tmp/:/proc/";

 

0
cIouddyy
cIouddyy
查下alias和root的区别
0
刘柳
刘柳

你估计是springboot的项目,有个static目录?

alias 换成root,把地址最后那个/去掉看看

CodePrayer
CodePrayer
额,没用,加了static目录也没用,主要是没弄懂为什么localhost可以,但是自定义的域名不可以。他们报的错是一样的,但是localhost可以完整显示出来
0
CodePrayer
CodePrayer

直接用localhost作绝对路径可以访问到资源

但是,自定义域名就不可以

而且好像和root和alias没什么关系,不管怎么改,localhost就是可以,但是自定义的域名就是不可以。难受~~~~

0
chentao106
chentao106
域名的dns解析配置了吗?
CodePrayer
CodePrayer
回复 @chentao106 : 谢谢,已经好了,清了下浏览器缓存就好了
chentao106
chentao106
回复 @CodePrayer : 你得先了解下域名解析的基本原理啊,要不然继续不下去的
chentao106
chentao106
回复 @CodePrayer : 浏览器怎么知道www.xucheng.com是本机呢?
CodePrayer
CodePrayer
这个没有注意,这应该怎么配置?本地主机也需要进行解析?
返回顶部
顶部