这是我example.conf
的nginx
配置文件:
server {
listen 80;
server_name api.example.net;
return 301 https://api.example.net$request_uri;
access_log off;
error_log /dev/stderr;
}
server {
listen 443 ssl;
root /var/www/example_api/public;
server_name api.example.net;
ssl_certificate /etc/letsencrypt/live/api.example.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.example.net/privkey.pem;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE, PATCH";
add_header Access-control-Allow-Headers "Content-Range, Authorization,X-Requested-With, counter, id_token, Keep-Alive, User-Agent, Cache-Control, Content-Type, MyApp-Handle-Errors-Generically";
add_header Access-Control-Expose-Headers "Content-Range, Authorization, id_token, Keep-Alive, User-Agent, Cache-Control, Content-Type, MyApp-Handle-Errors-Generically";
add_header Access-Control-Max-Age "31536000";
}
#location ~ ^/index\.php(/|$) {
# https://stackoverflow.com/questions/68350978/nginx-serving-only-but-not-any-other-files
location ~ \.php(/|$) {
try_files $uri $uri/ /index.php?$query_string;
fastcgi_pass api:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE, PATCH";
add_header Access-control-Allow-Headers "Content-Range, Authorization,X-Requested-With, counter, id_token, Keep-Alive, User-Agent, Cache-Control, Content-Type, MyApp-Handle-Errors-Generically";
add_header Access-Control-Expose-Headers "Content-Range, Authorization, id_token, Keep-Alive, User-Agent, Cache-Control, Content-Type, MyApp-Handle-Errors-Generically";
add_header Access-Control-Max-Age "31536000";
}
location ~ \.php$ {
return 404;
}
access_log off;
error_log /dev/stderr;
}
问题是当我从in发送POST
请求时,我收到此错误:POSTMAN
http
api.example.net/api/user/register/checkuser?phone=0123456789
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow,noarchive" />
<title>An Error Occurred: Method Not Allowed</title>
...
但是,如果将 URL 更改为https
,则没有问题:
https://api.example.net/api/user/register/checkuser?phone=0123456789
{"data":{"status":1},"meta":[]}
我做错什么了吗?
我应该提到我们从旧服务器迁移Caddy web server
到当前服务器nginx
,并且两者都是 Dockerized (仅额外信息)。
从RFC 7231第 6.4.2 节,关于301 Moved Permanently状态代码: