server {
server_name yoursite.com;
root /usr/share/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
ini 单页面应用程序的配置(框架:Angularjs,Web服务器:Nginx)
server {
listen 80 default deferred;
server_name myapp.com;
root /var/www/project-folder/;
# Nginx and Angularjs with html mode 5 - https://gist.github.com/cjus/b46a243ba610661a7efb
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
# Location of asset folder
location ~ ^/(assets)/ {
gzip_static on;
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript application/x-javascript
application/atom+xml;
expires max;
}
# Defines the URI that will be shown for the specified errors.
# error_page directives are inherited from the previous level
# only if there are no error_page directives defined on the current level.
# A uri value can contain variables.
error_page 404 /404.html;
# Sets the maximum allowed size of the client request body,
# specified in the “Content-Length” request header field.
# If the size in a request exceeds the configured value,
# the 413 (Request Entity Too Large) error is returned to the client.
# Please be aware that browsers cannot correctly display this error.
# Setting size to 0 disables checking of client request body size.
client_max_body_size 4G;
# The first parameter sets a timeout during which a keep-alive
# client connection will stay open on the server side.
# The zero value disables keep-alive client connections.
# The optional second parameter sets a value in the “Keep-Alive: timeout=time” response header field.
# Two parameters may differ.
keepalive_timeout 10;
}