I’m integrating an Iranian Stripe-like bank gateway provider with my Django application. When a user completes a successful purchase, the gateway redirects them back to our website using a predefined redirect URL to finish the deposit process.
However, some users encounter a “400 Bad Request” error (as shown in the screenshot below) when they are redirected back to our site. The error message indicates that “The plain HTTP request was sent to HTTPS port.
Here is my Nginx configuration:
server {
listen 80 default_server;
server_name _;
return 301 https://$server_name$request_uri;
}
server {
listen 8443 default_server ssl http2;
listen [::]:8443 ssl http2;
server_name [YOUR_SERVER_NAME];
ssl_certificate /etc/nginx/ssl/[YOUR_DOMAIN].cer;
ssl_certificate_key /etc/nginx/ssl/[YOUR_DOMAIN].cer.key;
access_log /project/logs/nginx/access.log;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options SAMEORIGIN;
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options nosniff;
add_header Referrer-Policy strict-origin-when-cross-origin;
location / {
try_files $uri @proxy_api;
}
location @proxy_api {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_pass http://web:8000;
}
location /static/ {
autoindex on;
alias /project/app/staticfiles/;
}
location /logs {
autoindex on;
alias /project/logs;
types {
text/plain log;
}
}
}
Screenshot: