前言
之前在ubuntu部署dotnetcore 程序还是比较简单的,今天试着部署一下静态文件,走了不少弯路,继续努力吧。
上传本地静态文件到服务器
2、我的静态html存放目录为
/usr/staticweb/gaodemap
nginx配置
server{ listen 80; server_name map.hubert.gq; root /usr/staticweb/gaodemap; location / { index Index.html Index.htm; autoindex on; autoindex_exact_size on; autoindex_localtime on; root /usr/staticweb/gaodemap; proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-FOR $proxy_add_x_forwarded_for; #此if为判断访问/目录有,匹配到该if,跳转到index配置项,即访问到index.html。 if ( !-e $request_filename ) { proxy_pass http://map.hubert.gq; } } }
配置完成之后校验一下配置文件是否有问题,以及重新加载nginx 配置
校验nginx配置文件是否有问题 nginx -t 重新加载nginx 配置 nginx -s reload
最后通过域名访问 访问成功
注意
1、root@www:~# 与 root@www:/# 的区别
root@ubuntu:/# 这个是根目录,对一般用户只读,root用户有所有权限
root@ubuntu:~# 这个是home目录,每个非root用户都会有自己的home目录
2、nginx 配置文件中 Index.html 是区分大小写的
如果配置文件写的是index.html 而服务器上是Index.html 这时候访问域名 则会出现目录索引 并不会直接跳转到Index.html