版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
1、root配置静态文件地址
server {
listen 80;
server_name _;
charset utf-8;
location /APP_FILE {
root /APP_FILE;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
auth_basic "Please enter user name and password";
auth_basic_user_file /etc/nginx/certs/passwd.db;
}
}
规则: root匹配的是location路径+root路径 ;也就是 IP/APP_FILE/APP_FILE
2、alias配置静态文件地址
# example 1
server {
listen 80;
server_name _;
charset utf-8;
location /APP_FILE {
alias /APP_FILE;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
auth_basic "Please enter user name and password";
auth_basic_user_file /etc/nginx/certs/passwd.db;
}
location /USER_FILE {
alias /USER_FILE;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
auth_basic "Please enter user name and password";
auth_basic_user_file /etc/nginx/certs/passwd.db;
}
}
--------------------------------------------------------------
# example 2
server {
location /html {
alias /usr/local/nginx/html;
index index.html index.htm;
}
location /html/ {
alias /usr/local/nginx/html/;
index index.html index.htm;
}
}
规则: alias是location匹配的路径需要和实际路径后面那节一样;alias、location必须两个同时存在或同时不存在即可
3、nginx静态文件配置优化
vim nginx.conf
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
}
sendfile:开启高效的文件传输模式
tcp_nopush:提升网络包的传输’效率
tcp_nodelay:提高网络包传输的实时性