Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use S3+nginx to realize the hosting of static sites

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use S3+nginx to achieve static site hosting", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use S3+nginx to achieve static site hosting" bar!

Requirements description:

The user has a static website, both html and js/css/img files, as well as a domain name static-website.com, which needs to forward the user's request for access from nginx to S3 at the back end.

The website folder structure is as follows

Website:-- index.html # homepage file-- js/ js directory-- css/ css directory-- img/ img directory 1. Upload files and set corresponding permissions

Use s3cmd to upload the website folder and set all files to public-read permissions, taking the bucket name as website-bucket as an example

S3cmd put website s3://website-bucket-recursive-acl-public2. Nginx forwarding configuration

The content of the setting / etc/nginx/conf.d/default.conf, is as follows. You can modify the specific content according to the actual situation.

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;} 3. Test access to curl http://static-website.com # you can see the contents of index.html thank you for reading, the above is "how to use S3+nginx to achieve static site hosting" content, after the study of this article, I believe you have a deeper understanding of how to use S3+nginx to achieve static site hosting this problem, the specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report