用nginx配置一个文件服务器,并解决中文乱码问题,配置文件
server {
listen 80;
server_name downloadapp.3vyd.com;
location / {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
add_header 'Access-Control-Allow-Headers' 'Range';
root /var/packages;
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
charset utf-8;
try_files $uri $uri/ /index.html;
}
}
image.png
如果,开放目录,当时不允许直接访问,只能访问指定路径下的html文件,nginx.conf的配置如下
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers *;
add_header Access-Control-Allow-Credentials true always;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
add_header Access-Control-Max-Age 1728000 always;
server {
listen 8088;
server_name localhost;
# location / {
# root /var/jenkins/report/admin/dist;
# try_files $uri $uri/ /index.html;
# index index.html;
# }
location /report {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
add_header 'Access-Control-Allow-Headers' '*';
return 204;
}
root /var/jenkins_home;
try_files $uri $uri/ /index.html;
index index.html;
}
location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
}
image.png
403
参考