2017-09-19 12 views
0

私はちょうどubuntu 16.04、nginx 1.10.3、php 7.0で新しいvpsをスピンアップし、私の作業サイトをコピーしました。古いサイトはphp5.6にあり、完璧に動作しました。

問題は、コード化されたプラス記号をスペースに変換していることです。 私は、ドキュメントインスペクタを使用して、それが本当の要求は%2Bと+をコードされていることを証明することができますが、まっすぐに、カールのテストも失敗します。これを引き起こすか、またはそれがnginxのですPHP拡張は

Test 1: 
curl "my_https_url" --data "details=asdf+%2B+asdf" --compressed 
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces 

Test 2: 
curl "my_https_url" --data-urlencoded "details=asdf+%2B+asdf" --compressed 
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect 

Test 3: 
$.post("my_https_url",{details:"asdf + asdf"}) 
Document Inspector Encoded Form Data: details=asdf+%2B+asdf 
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces 

Test 4: 
$.post("my_https_url",{details:"asdf %2B asdf"}) 
Document Inspector Encoded Form Data: details=asdf+%252B+asdf 
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect 

Test 5: 
$.post("my_https_url",{details:"asdf+%2B+asdf"}) 
Document Inspector Encoded Form Data: details=asdf%2B%252B%2Basdf 
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect 

Test 6: 
$.post("my_https_url",{details:encodeURI("asdf + asdf")}) 
Document Inspector Encoded Form Data: details=asdf%2520%2B%2520asdf 
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces 

Test 7: 
$.post("my_https_url",{details:encodeURIComponent("asdf + asdf")}) 
Document Inspector Encoded Form Data: details=details=asdf%2520%252B%2520asdf 
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect 

Test 8: 
$.post("my_https_url",$('<form><input name="details" value="asdf + asdf"></form>').serialize()) 
Document Inspector Encoded Form Data: details=details=details=asdf+%2B+asdf 
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces 

Test 9: 
$.post("my_https_url",encodeURIComponent($('<form><input name="details" value="asdf + asdf"></form>').serialize())) 
Document Inspector Encoded Form Data: details%3Dasdf%2520%252B%2520asdf 
array(0) {} <-- not working 

<?php 
var_dump($_POST); 
// I am expecting "asdf + asdf" 

ありますか?私は両方のconfigsを含んだ。

のphpinfo:https://ibb.co/jZCxeQ

nginxの設定:

server { 
    listen 80; 

# access_log /var/log/nginx/website.access_log; 
    error_log /var/log/nginx/website.error_log; 
    set $oldhost $host; 
    root PHP_FILES_LOCATION; 
    location ~* \.(?:ico|css|js|gif|jpg|png|html|htm)$ { 
     try_files $uri $uri/ /index.php; 
     expires 3d; 
     add_header Pragma public; 
     add_header Cache-Control "public"; 
    } 
    location = /favicon.ico { 
     log_not_found off; 
     access_log off; 
    } 
    location = /robots.txt { 
     allow all; 
     log_not_found off; 
     access_log off; 
    } 
    location/{ 
     index index.php index.htm index.html; 
     try_files $uri $uri/ /index.php; 
    } 

    location ~ json.php$ { 
     try_files $uri $uri/ /index.php; 
    # location ~ \..*/.*\.php$ {return 404;} 
     # expires 3d; add_header Pragma public; add_header 
     # Cache-Control "public"; 
     fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
     fastcgi_buffers 16 16k; 
     fastcgi_buffer_size 32k; 
     # fastcgi_index index.php; 
     client_max_body_size 80m; 
     fastcgi_intercept_errors on; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
    location ~ .php$ { 
     #location ~ \..*/.*\.php$ {return 404;} 
     try_files $uri $uri/ /404.php?$args; 
     #expires 1d; 
     add_header Pragma public; 
     client_max_body_size 80m; 
     add_header Cache-Control "public"; 
     fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
     fastcgi_buffers 16 16k; 
     fastcgi_buffer_size 32k; 
     fastcgi_intercept_errors on; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 
+3

エンコードされたURLで '+'の意味を認識しているかどうかは不明ですか?そうでない場合はhttps://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20をご覧ください。 – alexis

+0

はい、URLのプラス記号はスペースを表すことができます。だから私はスペース符号化されたバージョン%2Bを送ったのですが、それは決してスペースとして扱われるべきではありません。 –

+0

'--data-urlencode" details = asdf asdf "'を試したことがありますか? –

答えて

0

あなたがデータを提出する前に、あなたは自分の価値観に特殊文字をエンコードする必要があります。値をencodeURIComponentにラップします。

$.post("my_https_url",{details:encodeURIComponent("asdf + asdf")})

+0

いいえ、まだ動作しません。私はこれをテスト6として追加しました。 –

+0

@NickSchild投稿を編集しました。それは 'encodeURI'の代わりに' encodeURIComponent'でなければなりません –

+0

コードのみの回答は、質問の問題の解決方法を説明していないため、推奨されません。あなたの答えを更新して、これが何をし、どのように問題を解決するのかを説明してください。 [よくある回答を書くにはどうすればいいですか]をよく読んでください(https://stackoverflow.com/help/how-to-answer) – FluffyKitten

0

解決しよう:私は、私はメインのドメインにプロキシサーバーを持っていたことを忘れてしまいました。 @johnBakerのサブドメインを作成してプロキシサーバーをバイパスし、それが正常に機能するようにしました。プロキシ設定への簡単な修正とそれは動作します!私の野生のガチョウの追跡に参加してくれてありがとうございます。

+0

問題を引き起こしていたプロキシ設定は何ですか? –