我实际上有这个工作,但我想知道我是否以最有效的方式做到这一点,或者我是否可以对我的conf文件进行任何改进。这是我试图做的事情:
这是我当前的工作conf文件:
server {
listen 80;
server_name www.example.com;
client_max_body_size 50M;
root /var/www/mysite;
location = /index.html {
}
# map everything in base dir to one file
location ~ ^/[^/]*$ {
rewrite ^/[^/]*$ /index.html;
}
location ~ ^/css/ {
}
location ~ ^/js/ {
}
}
我的最终配置文件,在负载测试下更快,比原始更简单,在这里:
server {
listen 80;
server_name example.com;
root /var/www/register;
location = /index.html {
}
# Default location, request will fallback here if none other
# location block matches
location / {
rewrite ^.*$ /index.html redirect; # 'root' location '/'
}
location /css/ {
}
location /js/ {
}
}
答案 0 :(得分:1)
我不确定我是否正确,但请检查此答案,您始终要服务index.html
,因此它应该是默认位置location /
server {
server_name example.com www.example.com;
client_max_body_size 50M;
root /var/www/mysite;
index index.html;
location / {
try_files index.html =404;
}
location /(css|js) {
try_files $uri =404;
}
}