【问题标题】:Laravel 5 Form Posting gives 403 ErrorLaravel 5 表单发布给出 403 错误
【发布时间】:2016-07-25 19:01:19
【问题描述】:

我有一个由 JavaScript 填充和提交的表单。该表单由 Laravel Form Builder 构建。这是表单的代码:

{!!Form::open(['url' => URL::to('billing/payments', array(), true ), 'id' => 'frmRebill'])!!}
    {!!Form::hidden('plan', '', ['id' => 'plan'])!!}
    {!!Form::hidden('annual', '', ['id' => 'annual'])!!}
{!!Form::close()!!}

如果从http://server.com/billing 访问表单并提交到https://server.com/billing/paymenthttp://server.com/billing/payment,则可以正常工作。

但是当从https://server.com/billing 访问表单并提交到https://server.com/billing/payment 时,它会出现 403 错误。

我正在使用 Nginx。这里是 Nginx 虚拟主机文件:

server {
    listen 80;
    server_name server.com
    charset utf-8;
    sendfile off;
    client_max_body_size 10m;
    index index.php;

    error_log /var/log/nginx/error.log debug;
    access_log /var/log/nginx/access.log;

    root /var/www/server/public;

    location /ping.html {
            return 200 'pong';
    }

location ~ ^/billing/(.+(?:css|js|woff|woff2|ttf))$ {
            alias /var/www/billing/public/$1;
            access_log off;
    }

#billing code in laravel5
location /billing/ {

    error_log /var/log/nginx/mkj-error.log debug;

    alias /var/www/billing/public;
    ## Check for file existing and if there, stop ##
    if (-f $request_filename) {
            break;
    }

    ## Check for file existing and if there, stop ##
    if (-d $request_filename) {
            break;
    }
    index index.php;
    try_files $uri $uri/ @billing;
}
location @billing {
    rewrite /billing/(.*)$ /billing/index.php?/$1 last;
}

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    set $php_root /var/www/s/public;
    if ($request_uri ~ /billing) {
        set $php_root /var/www/billing/public;
        }
        fastcgi_param PATH_TRANSLATED $php_root/index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_param REMOTE_ADDR $http_x_real_ip;
        include fastcgi_params;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_read_timeout 120;
    }

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


    location ~ /\.ht {
        deny all;
    }
}    

注意:csrf 令牌也是由表单生成并保存在会话中的。 有人可以弄清楚问题是什么以及解决方案是什么?

【问题讨论】:

    标签: php post nginx laravel-5 http-status-code-403


    【解决方案1】:

    您需要配置 HTTPS 服务器。您的配置文件仅侦听 http 请求。

    server {
        listen              443 ssl;
        server_name         www.example.com;
        ssl_certificate     www.example.com.crt;
        ssl_certificate_key www.example.com.key;
        ...
    }
    

    这里是如何http://nginx.org/en/docs/http/configuring_https_servers.html的链接

    【讨论】:

    • 我正在使用亚马逊负载均衡器,它接受 https 上的请求并将其重定向到内部 VPC 的 http。
    猜你喜欢
    • 1970-01-01
    • 2023-04-04
    • 2012-07-09
    • 1970-01-01
    • 2015-06-19
    • 2019-04-06
    • 2014-09-18
    • 2018-08-03
    • 2020-10-28
    相关资源
    最近更新 更多