doushi2845 2016-04-05 17:25
浏览 75

Laravel 5 Form Posting给出403错误

I have a form which is populated and submitted by JavaScript. The form is build by Laravel Form Builder. Here is the code for the Form:

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

If form is accessed from http://server.com/billing and submitted to https://server.com/billing/payment or http://server.com/billing/payment, it works fine.

But when form is accessed from https://server.com/billing and submitted to https://server.com/billing/payment it gives the 403 error.

I'm using Nginx. Here is the Nginx virtual host file:

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;
    }
}    

Note: the csrf token is also same generated by the form and saved in session. Can some one please figure out what the problem is and what is the solution?

  • 写回答

1条回答 默认 最新

  • drbfxb977777 2016-04-05 18:32
    关注

    You need to configure HTTPS server. Your config file only listens for http requests.

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

    Here is a link on how to http://nginx.org/en/docs/http/configuring_https_servers.html

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算