Laravel路由和POST问题



我使用Laravel提交post请求时遇到问题。以下内容在本地使用docker与Laravel 9.21.6和PHP 8.1.0一起工作。当我尝试使用Laravel 9.21.6和PHP 8.1.8在运行NGINX的实时服务器上运行时,我一无所获。我错过了什么?

Route::post('orders', function (Request $request) {
return ($request);
});

如果我尝试以下卷曲请求:

curl -v -X POST -d "{'order':18}" "http://localhost/api/orders"

我打印订单:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:80...
* Connected to localhost (127.0.0.1) port 80 (#0)
> POST /api/orders HTTP/1.1
> Host: localhost
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length: 12
> Content-Type: application/x-www-form-urlencoded
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Host: localhost
< Date: Sun, 31 Jul 2022 18:41:08 GMT
< Connection: close
< X-Powered-By: PHP/8.1.0
< Cache-Control: no-cache, private
< Date: Sun, 31 Jul 2022 18:41:08 GMT
< Content-Type: application/json
< X-RateLimit-Limit: 60
< X-RateLimit-Remaining: 59
< Access-Control-Allow-Origin: *
< 
* Closing connection 0
{"{'order':18}":null}% 

但如果我在服务器上尝试:

curl -v -X POST -d "{'order':18}" "https://server.com/api/orders"

我一无所获:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 54.145.34.166:443...
* Connected to api.wenusvi.com (54.145.34.166) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (OUT), TLS handshake, Client hello (1):
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=wenusvi.com
*  start date: Jun 18 19:22:18 2022 GMT
*  expire date: Sep 16 19:22:17 2022 GMT
*  subjectAltName: host "api.wenusvi.com" matched cert's "api.wenusvi.com"
*  issuer: C=US; O=Let's Encrypt; CN=R3
*  SSL certificate verify ok.
> POST /api/orders HTTP/1.1
> Host: api.wenusvi.com
> User-Agent: curl/7.79.1
> Accept: */*
> Connection: close
> Content-Length: 12
> Content-Type: application/x-www-form-urlencoded
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx/1.18.0 (Ubuntu)
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: close
< Cache-Control: no-cache, private
< Date: Sun, 31 Jul 2022 18:40:55 GMT
< X-RateLimit-Limit: 60
< X-RateLimit-Remaining: 59
< Access-Control-Allow-Origin: *
< 
* Closing connection 0

经过多次尝试和错误,该问题与php-fpm有关。服务器似乎正在缓存输出。最初,这个URL没有输出任何结果,所以服务器缓存了";数据";并且任何进一步的调用都返回空数据。重新启动php-fpm是有效的,所以我做了更多的搜索,并看到了一篇建议将opcache更改为0的文章。看见https://serverfault.com/questions/991843/why-does-php-fpm-sometimes-get-stuck-serving-old-files

最新更新