您好,登錄后才能下訂單哦!
請求超時!
這篇文章主要講解了“如何利用S3+nginx實現(xiàn)靜態(tài)站點的托管”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“如何利用S3+nginx實現(xiàn)靜態(tài)站點的托管”吧!
需求描述:用戶有一個靜態(tài)website,都是html和js/css/img這些文件,同時還有一個域名static-website.com,需要將用戶訪問的請求由nginx轉發(fā)到后端的S3。
website文件夾結構如下
website: -- index.html #首頁文件 -- js/ js目錄 -- css/ css目錄 -- img/ img目錄
使用s3cmd上傳website文件夾并設置所有文件為public-read權限,以bucket名稱為website-bucket為例
s3cmd put website s3://website-bucket --recursive --acl-public
設置/etc/nginx/conf.d/default.conf,,內(nèi)容如下,具體內(nèi)容各位根據(jù)實際情況進行修改
server { listen 80; server_name static-website.com *.static-website.com; location ~ ^/(img|js|css)/ { proxy_set_header Host 'website-bucket.s3.endpoint.com'; proxy_pass http://website-bucket.s3.endpoint.com:80; } location /index.html { proxy_set_header Host 'website-bucket.s3.endpoint.com'; proxy_pass http://website-bucket.s3.endpoint.com:80; } location / { rewrite ^/$ /index.html last; } }
curl http://static-website.com #可以看到index.html的內(nèi)容
感謝各位的閱讀,以上就是“如何利用S3+nginx實現(xiàn)靜態(tài)站點的托管”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對如何利用S3+nginx實現(xiàn)靜態(tài)站點的托管這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。
億速云公眾號
手機網(wǎng)站二維碼
Copyright ? Yisu Cloud Ltd. All Rights Reserved. 2018 版權所有
廣州億速云計算有限公司粵ICP備17096448號-1 粵公網(wǎng)安備 44010402001142號增值電信業(yè)務經(jīng)營許可證編號:B1-20181529