Nginx静态网站的配置-跨域,盗链

防盗链配置支持

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

跨域

server {
  listen       80;
  server_name  localhost;

  add_header Access-Control-Allow-Origin *;
  add_header Access-Control-Allow-Headers X-Requested-With;
  add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
  if ($request_method = 'OPTIONS') {
    return 204;
  }
  location / {
    root   /mnt/d/mydesign/linux/nginx/demo;
    index  index.html index.htm;
  }

  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   html;
  }
}

server {
        listen       8088;
        server_name  localhost;
        location /VASC{
            alias   /VASC;
            try_files $uri $uri/ /index.html=404;
            index  index.html index.htm;
        }
        location /HASC{
            alias   /HASC;
            try_files $uri $uri/ /index.html=404;
            index  index.html index.htm;
        }
        location @router {
            rewrite ^.*$ /index.html last;
        }
        location /ASCWEB/api/yunyingapi/{
            rewrite  ^.+yunyingapi/?(.*)$ /$1 break;
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers X-Requested-With;
            add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
            if ($request_method = 'OPTIONS') {
                return 204;
            }
            proxy_pass http://124.126.16.98:8007/;
        }
}

静态网站部署

单一路径映射

  server {
        listen       80;
        server_name  localhost;
        location / {
            root   /mnt/d/mydesign/linux/nginx/demo;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

映射多个html

  server {
        listen       80;
        server_name  localhost;
        location / {
            root   /mnt/d/mydesign/linux/nginx/demo;
            index  index.html index.htm;
        }

#拼接到root后面  
    		location /mmd {
            root   /mnt;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
根据提供的引用内容,fastdfs-nginx-module的配置跨域可以通过在nginx配置文件中增加以下配置来实现\[3\]。具体配置如下: ``` location / { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header Access-Control-Expose-Headers 'Content-Length,Content-Range'; } ``` 这段配置会在响应头中添加Access-Control-Allow-Origin字段,允许所有来源的请求访问。同时,还会添加Access-Control-Allow-Methods字段,指定允许的请求方法,以及Access-Control-Allow-Headers字段,指定允许的请求头。最后,还会添加Access-Control-Expose-Headers字段,指定允许客户端获取的响应头。 请注意,这只是最简单的配置示例,实际情况中可能需要根据具体需求进行调整。 #### 引用[.reference_title] - *1* *2* [nginx配置fastdfs模块内容时报错unknown directive ngx_fastdfs_module in /usr/local/nginx/conf/nginx.conf:50](https://blog.csdn.net/Cafune_f/article/details/125571122)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [FastDFS+nginx+fastdfs-nginx-module服务器配置详解](https://blog.csdn.net/tjcyjd/article/details/69663348)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值