Nginx配置访问服务器静态文件

1.centos系统中访问/usr/local/nginx/conf,修改nginx.conf

server{

     listen 端口

     server_name localhost;

     location / {

          root html;

          index index.html index.htm;

          }

     location /文件所在文件夹名称/{

          alias 文在所在服务器路径;

          add_header 'Access-Cintrol-Allow-Origin' '*';

          add_header 'Access-Control-Allow-Credentials' 'true';

          }

}

2.在/usr/local/nginx/sbin/路径下,输入:./nginx -t ,显示ok标识配置正确

3.在/usr/local/nginx/sbin/路径下,输入:./nginx -s reload,重启nginx服务

4.在浏览器中输入ip:端口/文件所在文件夹名称/文件名称,你想要浏览的文件就可以访问了。

你可能感兴趣的:(nginx)