码迷,mamicode.com
首页 > 其他好文 > 详细

laravel环境 配置Nginx跨域设置

时间:2020-08-20 19:02:43      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:log   lda   cgi   tool   add   html   unix   res   off   

nginx配置
 server {
     listen 80;
     server_name laravel.hanye.com;
     access_log /data/wwwlogs/laravel_access_nginx.log main;
     error_log /data/wwwlogs/laravel_error_nginx.log;
     root /home/hanye/laravel/public;
     index index.html index.htm index.php;
    location / {
       root /home/qa/laravel/public;
       index index.html index.htm index.php;
       #CROS, 支持预发送请求
             if ($request_method = ‘OPTIONS‘) {
                     add_header ‘Access-Control-Allow-Origin‘ ‘*‘ always;
                     add_header ‘Access-Control-Allow-Methods‘ ‘GET, POST, PUT, DELETE, PATCH,OPTIONS‘;
                     add_header ‘Access-Control-Allow-Headers‘ ‘X-Requested-With,Content-Type,Authorization‘;
                     add_header ‘Access-Control-Max-Age‘ 1728000;
                     add_header ‘Content-Type‘ ‘text/plain; charset=utf-8‘;
                     add_header ‘Content-Length‘ 0;
                     return 204;
              }
      ##此处要注意写到location / 里面
      if (!-e $request_filename){
    rewrite (.*) /index.php last;
               }
     }
       ## 链接php
       location ~ [^/]\.php(/|$) {
         fastcgi_pass unix:/data/phpsock/php-cgi.sock;
         fastcgi_index index.php;
         include fastcgi.conf;
         error_page 405 =200 http://zz.1fangxin.net;
         #CROS, 支持RESTFul模式
             add_header ‘Access-Control-Allow-Origin‘ ‘*‘ always;
             add_header ‘Access-Control-Allow-Methods‘ ‘GET, POST,PUT,DELETE,PATCH,OPTIONS‘;
             add_header ‘Access-Control-Allow-Headers‘ ‘X-Requested-With,Content-Type,Authorization‘;
           }
       location ^~ /data/ {
                return 403;
       }
       location ^~ /plus/ {
                return 403;
       }
       location ^~ /install/ {
               return 403;
       }
       location ^~ /templets/ {
               return 403;
       }
       if ($http_user_agent ~ "FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|^$" )
       {
            return 403;
       }
       if ($http_user_agent ~* (Scrapy|HttpClient))
       {
            return 403;
       }

       location ~*(\/\/.*$) {
        return 403;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
             expires 30d;
             access_log off;
        }
       location ~ .*\.(js|css)?$ {
         expires 7d;
         access_log off;
       }
     } 

laravel环境 配置Nginx跨域设置

标签:log   lda   cgi   tool   add   html   unix   res   off   

原文地址:https://blog.51cto.com/9025736/2521318

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!