前言
之前在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