I am having an Nginx server, with uwsgi and Wordpress installed on it. So the problem is that whenever I am trying to send a POST request to uwsgi application it fails with the error 405, but the method is allowed on server so I don't know why it happens. Here is the nginx.conf file:
server {
listen 80;
server_name hrspot.me;
return 301 https://hrspot.me$request_uri;
}
server {
listen 443 ssl;
server_name hrspot.me;
index index.php index.html index.htm;
root /var/www/html;
ssl_certificate /etc/ssl/bundle.crt;
ssl_certificate_key /etc/ssl/www.hrspot.me.key;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
client_max_body_size 1024m;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off;
}
location = /robots.txt {
log_not_found off;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location /api {
include uwsgi_params;
uwsgi_pass hrspotme_server:8080;
}
}
And here is the method in flask app:
...
@account.route('/api/register', methods=['POST'])
def route_api_register():
form = RegisterForm()
return api_register(form)
...
As you can see that is the POST method. For some reason UWSGI perceives it as a GET request And here is the log for this method from UWSGI:
[pid: 10|app: 0|req: 2/3] ip_address () {44 vars in 686 bytes} [Fri Jul 10 13:01:55 2020] GET /api/register => generated 178 bytes in 17 msecs (HTTP/1.1 405) 3 headers in 118 bytes (1 switches on core 1)
So I understand that some kind of problem with the settings.
HOW I MAKE A REQUEST:
LOGS WHEN I TRY TO SEND POST REQUEST TO /api/auth:
ip - - [10/Jul/2020:13:51:06 +0000] "POST /api/auth HTTP/1.1" 301 169 "-" "PostmanRuntime/7.26.1" "-"
ip - - [10/Jul/2020:13:51:06 +0000] "GET /api/auth HTTP/1.1" 405 178 "http://hrspot.me/api/auth" "PostmanRuntime/7.26.1"
UPD:
I tried to specify https in front of the url in the postman and it worked, so it seems an error that when I initially call on the http request, it incorrectly redirects it to the https request, changing the method from POST to GET.