Uygulamaların genellikle dinamik istekleri işlemenin yanı sıra JavaScript, resimler ve CSS gibi statik dosyalar da sunması gerekir. Standart ortamdaki uygulamalar, Cloud Storage gibi bir Google Cloud seçeneğinden statik dosyalar sunabilir, bunları doğrudan sunabilir veya bir üçüncü taraf içerik dağıtım ağını (CDN) kullanabilir. Statik sitenizi Google Cloud'da barındırmak, geleneksel bir barındırma kullanmaktan daha düşük maliyetli olabilir Google Cloud ücretsiz bir katman sağladığından sağlayıcı
## Cloud Storage'dan dosya sunma
Cloud Storage, dinamik web uygulamaları için statik varlıkları barındırabilir. Doğrudan uygulamanızdan hizmet vermek yerine Cloud Storage kullanmanın avantajları şunlardır:
- Bulut Depolama esas olarak bir içerik dağıtım ağı olarak çalışır. Bu herhangi bir özel yapılandırma gerektirmez çünkü varsayılan olarak okunabilir herhangi bir nesne küresel Bulut Depolama ağında önbelleğe alınır
- Statik varlıkların sunumunun Cloud Storage'a boşaltılmasıyla uygulamanızın yükü azaltılacaktır. Sahip olduğunuz statik varlığa ve erişim sıklığına bağlı olarak bu, uygulamanızı çalıştırma maliyetini önemli ölçüde azaltabilir.
- Cloud Storage'da içeriğe erişim için bant genişliği ücretleri genellikle daha düşük olabilir
Varlıklarınızı Cloud Storage'a yükleyebilirsiniz.
gsutil komut satırı aracı
veya Bulut Depolama API'si
Google Cloud İstemci Kitaplığı, bir App Engine uygulamasında Cloud Storage ile veri depolamak ve almak için Cloud Storage'a deyimsel bir Go 1.11 istemcisi sağlar
Cloud Storage paketinden hizmet sunma örneği
Bu basit örnek, bir Cloud Storage paketi oluşturur ve Google Cloud CLI'yi kullanarak statik öğeleri yükler:
Bir kova oluşturun. Paketinize proje kimliğinizin adını vermeniz yaygındır ancak zorunlu değildir. Paket adı genel olarak benzersiz olmalıdır
gsutil mb gs-paket-adınız>ACL'yi paketteki öğelere okuma erişimi verecek şekilde ayarlayın
gsutil defacl herkesin okuyabileceği gs-paket-adınız>ayarlandı
Öğeleri pakete yükleyin.
rsynccommand genellikle varlıkları yüklemenin ve güncellemenin en hızlı ve en kolay yoludur. Ayrıca kullanabilirsiniz
cp
gsutil -m rsync -r ./static gs-paket-adınız>/statik
Artık statik varlıklarınıza şu adresten erişebilirsiniz:
httpsstorage.googleapis.com//static
For more details on how to use Cloud Storage to serve static assets, including how to serve from a custom domain name, refer to How to Host a Static Website
Serving files from other Google Cloud services
You also have the option of using Cloud CDN or other Google Cloud storage services
## Serving files directly from your app
To serve static files for Go 1.11 in the standard environment,
you define the handlers in your
app.yaml file using either the
static_dir
or
static_files
elements
The content in the static files or static directories are unaffected
by the scaling settings in your
app.yaml file. Requests to static files or
static directories are handled by the App Engine infrastructure
directly, and do not reach the language runtime of the application
Configuring your static file handlers
To configure your app to serve the
./public directory from the
/static URL,
you define a handler in your
app.yaml file
The following demonstrates how to serve the static files of a sample
app's
./public directory. The template for this app's
index.html page
instructs the browser to load the
main.css file, for example:
/css/main.css">
The
./public directory is defined in the
static_dir element of the project's
app.yaml file:
handlers: - url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico - url: /static static_dir: public - url:secure: always redirect_http_response_code: 301 script: auto
The
handlers section in the above example handles three URL patterns:
The
/favicon.icohandler maps a request specifically for
/favicon.icoto a file named
favicon.icoin the app's root directory
The
/statichandler maps requests for URLs that start with
/static. When App Engine receives a request for a URL beginning with
/static, it maps the remainder of the path to files in the
./publicdirectory. If an appropriate file is found in the directory, the contents of that file are returned to the client
The
handler matches all other URLs and directs them to your app
URL path patterns are tested in the order they appear in
app.yaml, therefore
the pattern for your static files should be defined before the
pattern
For more information, see the
app.yaml
reference
## Serving from a third-party content delivery network
You can use any external third-party CDN to serve your static files and cache dynamic requests but your app might experience increased latency and cost
For improved performance, you should use a third-party CDN that supports CDN Interconnect.