加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Nginx添加标头PHP FPM返回错误

发布时间:2020-12-13 20:53:44 所属栏目:Nginx 来源:网络整理
导读:我正在使用带有Nginx和PHP-FPM的Laravel 4来为应用程序提供服务. 该应用程序实现了API,但是我向Nginx添加了一些相当开放的CORS规则,这些规则似乎运行良好. 每当应用程序抛出错误时,Nginx似乎都不会在响应中添加标头.有什么方法可以强制执行此操作,而不必安装

我正在使用带有Nginx和PHP-FPM的Laravel 4来为应用程序提供服务.

该应用程序实现了API,但是我向Nginx添加了一些相当开放的CORS规则,这些规则似乎运行良好.

每当应用程序抛出错误时,Nginx似乎都不会在响应中添加标头.有什么方法可以强制执行此操作,而不必安装更多的标头扩展名?

我的配置如下:

server {
    listen 80;
    server_name mediabase.local;
    root /home/vagrant/mediabase/public;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;

    add_header Access-Control-Allow-Origin "*";
    add_header Access-Control-Allow-Methods "GET,OPTIONS,POST,HEAD,DELETE,PUT";
    add_header Access-Control-Allow-Headers "Authorization,X-Requested-With,Content-Type,Origin,Accept";
    add_header Access-Control-Allow-Credentials "true";
    add_header Access-Control-Max-Age: 86400;


    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/mediabase.local-error.log error;

    error_page 404 /index.php;

    sendfile off;

    location ~ .php${
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;

    add_header Access-Control-Allow-Origin "*";
    add_header Access-Control-Allow-Methods "GET,Accept";
    add_header Access-Control-Allow-Credentials "true";
    add_header Access-Control-Max-Age: 86400;

    }

    location ~ /.ht {
        deny all;
    }
}
最佳答案
Nginx的docs say that add_header

Adds the specified field to a response header provided that the
response code equals 200,201,204,206,301,302,303,304,or 307
.

作为HttpHeadersMoreModule的替代方案,您可以在Laravel中添加标头,方法如下:https://stackoverflow.com/a/17550224

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读