Для отправки контактной формы настроена связка nginx+django+ajax.
Внезапно стала возникать ошибка при отправке формы на сайте. Форма не приходит,
в логах ошибка - upstream prematurely closed connection while reading response header from upstream.
Ajax:
$('#send_form').submit(function (e) {
e.preventDefault();
$.ajax({
type: 'get',
url: '/send',
data: $(this).serialize(),
success: function () {
alert('form was submitted');
}
});
});
Django:
from django.views.generic import View
from django.http import HttpResponse
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.conf import settings
class Send(View):
def get(self, request, *args, **kwargs):
print(request.GET)
message = render_to_string('email.html', {'data': request.GET})
send_mail(
'New message on site xxxxx.ru,
message,
settings.DEFAULT_FROM_EMAIL,
[settings.EMAIL_DEFAULT_TO],
fail_silently=False,
)
return HttpResponse(status=200)
Nginx:
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 150;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
server {
listen 80;
server_name xxxxx.ru;
location /static/ {
root /var/www/xxxxxxxxx;
index index.html index.htm index.php;
}
location / {
root /var/www/xxxxxxxx;
proxy_pass http://127.0.0.1:8888;
index index.html index.htm index.php;
}
}
server {
listen 80;
server_name xxxxxxx;
location /static/ {
root /var/www/xxxxxxx;
index index.html index.htm index.php;
}
location / {
root /var/www/xxxxxxx;
proxy_pass http://127.0.0.1:8888;
index index.html index.htm index.php;
}
}
Форма:
<form id='send_form'>
<input type="text" name='name' placeholder="Name" required>
<input type="email" name='email' placeholder="E-mail" required>
<textarea name="message" id="" cols="30" rows="10" placeholder="Message"></textarea>
<input name='submit' type="submit" value='Send'>
</form>
Серьезно ничего не менял, скриптов не добавлял, не понимаю в чем дело.