首页 > 其他 > 详细

Nginx配置

时间:2020-04-22 17:41:21      阅读:42      评论:0      收藏:0      [点我收藏+]

1、导入外部文件,使用include

include test.conf;

内容如下:

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
    server {
        listen       81;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

这样,可以很方便的在外部维护配置

2、Nginx 跨域配置支持

    server {
        listen       80;
        server_name  localhost;

    #允许跨域请求的域,*代表所有
    add_header ‘Access-Control-Allow-Origin‘ *;
    #允许带上cookie请求
    add_header ‘Access-Control-Allow-Credentials‘ ‘true‘;
    #允许请求的方法,比如 GET/POST/PUT/DELETE
    add_header ‘Access-Control-Allow-Methods‘ *;
    #允许请求的header
    add_header ‘Access-Control-Allow-Headers‘ *;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

3、Nginx 防盗链配置支持

    server {
        listen       81;
        server_name  localhost;

    #对源站点验证
    valid_referers *.imooc.com; 
    #非法引入会进入下方判断
    if ($invalid_referer) {
        return 404;
    } 

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

 

Nginx配置

原文:https://www.cnblogs.com/sirius-sen/p/12753441.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!