Я работал над приложением Flask, и при развертывании мне пришлось использовать Gunicorn и Nginx. Теперь он доступен, однако при перенаправлении из Flask адрес перенаправляется на список, состоящий из моего домена дважды, например
https://cards.jellywx.co.uk,card.jellywx.co.uk/game?id=12
.
Мой файл конфигурации для Nginx (в наличии на сайтах) выглядит как
server {
listen 80;
server_name http://cards.jellywx.co.uk;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name https://cards.jellywx.co.uk;
ssl_certificate /etc/letsencrypt/live/cards.jellywx.co.uk/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/cards.jellywx.co.uk/privkey.pem;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
include proxy_params;
proxy_pass http://localhost:8000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /socket.io {
include proxy_params;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://localhost:8000/socket.io;
}
location /static {
alias /var/www/cards-against-humanity/app/static;
expires 30d;
}
}
и для перенаправлений я просто использую return redirect( url_for( 'game', id=game_id ) )
Источник доступен по адресу https://github.com/jellywx/cards-against-humanity
Любая помощь очень ценится, спасибо.
Журнал ошибок Nginx:
2018/08/29 14:25:26 [notice] 5780#5780: signal process started
2018/08/29 12:32:01 [warn] 5891#5891: server name "http://cards.jellywx.co.uk" has suspicious symbols in /etc/nginx/sites-enabled/cards:4
2018/08/29 12:32:01 [warn] 5891#5891: server name "https://cards.jellywx.co.uk" has suspicious symbols in /etc/nginx/sites-enabled/cards:12
2018/08/29 12:32:01 [warn] 5891#5891: could not build optimal proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64; ignoring proxy_headers_hash_bucket_size
2018/08/29 12:32:01 [notice] 5891#5891: signal process started
2018/08/29 12:55:01 [error] 5892#5892: *1258 connect() failed (111: Connection refused) while connecting to upstream, client: 82.24.5.236, server: https://cards.jellywx.co.uk, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "cards.jellywx.co.uk"
2018/08/29 13:23:53 [error] 5892#5892: *1328 upstream prematurely closed connection while reading response header from upstream, client: 82.24.5.236, server: https://cards.jellywx.co.uk, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "cards.jellywx.co.uk"
2018/08/29 13:23:54 [error] 5892#5892: *1328 upstream prematurely closed connection while reading response header from upstream, client: 82.24.5.236, server: https://cards.jellywx.co.uk, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "cards.jellywx.co.uk"
2018/08/29 13:24:12 [error] 5892#5892: *1328 upstream prematurely closed connection while reading response header from upstream, client: 82.24.5.236, server: https://cards.jellywx.co.uk, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "cards.jellywx.co.uk"
2018/08/29 13:24:13 [error] 5892#5892: *1328 upstream prematurely closed connection while reading response header from upstream, client: 82.24.5.236, server: https://cards.jellywx.co.uk, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "cards.jellywx.co.uk"
2018/08/29 13:24:58 [warn] 6537#6537: server name "http://cards.jellywx.co.uk" has suspicious symbols in /etc/nginx/sites-enabled/cards:4
2018/08/29 13:24:58 [warn] 6537#6537: server name "https://cards.jellywx.co.uk" has suspicious symbols in /etc/nginx/sites-enabled/cards:12
2018/08/29 13:24:58 [warn] 6537#6537: could not build optimal proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64; ignoring proxy_headers_hash_bucket_size
2018/08/29 13:24:58 [notice] 6537#6537: signal process started
root@vps578947:/var/log/nginx#
Системный журнал от Gunicorn:
Aug 29 13:27:05 vps578947 systemd[1]: Stopped cards-against-humanity.service.
Aug 29 13:27:05 vps578947 systemd[1]: cards-against-humanity.service: Start request repeated too quickly.
Aug 29 13:27:05 vps578947 systemd[1]: cards-against-humanity.service: Failed with result 'exit-code'.
Aug 29 13:27:05 vps578947 systemd[1]: Failed to start cards-against-humanity.service.
Aug 29 13:27:08 vps578947 systemd[1]: /etc/systemd/system/cards-against-humanity.service:2: Unknown lvalue 'Name' in section 'Unit'
Aug 29 13:27:08 vps578947 systemd[1]: Started cards-against-humanity.service.
Aug 29 13:27:09 vps578947 gunicorn3[6740]: [2018-08-29 13:27:09 +0000] [6740] [INFO] Starting gunicorn 19.7.1
Aug 29 13:27:09 vps578947 gunicorn3[6740]: [2018-08-29 13:27:09 +0000] [6740] [INFO] Listening at: https://127.0.0.1:8000 (6740)
Aug 29 13:27:09 vps578947 gunicorn3[6740]: [2018-08-29 13:27:09 +0000] [6740] [INFO] Using worker: eventlet
Aug 29 13:27:09 vps578947 gunicorn3[6740]: [2018-08-29 13:27:09 +0000] [6763] [INFO] Booting worker with pid: 6763
Aug 29 13:43:14 vps578947 gunicorn3[6740]: [2018-08-29 13:43:14,687] ERROR in app: Exception on /game [GET]
Aug 29 13:43:14 vps578947 gunicorn3[6740]: Traceback (most recent call last):
Aug 29 13:43:14 vps578947 gunicorn3[6740]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2292, in wsgi_app
Aug 29 13:43:14 vps578947 gunicorn3[6740]: response = self.full_dispatch_request()
Aug 29 13:43:14 vps578947 gunicorn3[6740]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1815, in full_dispatch_request
Aug 29 13:43:14 vps578947 gunicorn3[6740]: rv = self.handle_user_exception(e)
Aug 29 13:43:14 vps578947 gunicorn3[6740]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1718, in handle_user_exception
Aug 29 13:43:14 vps578947 gunicorn3[6740]: reraise(exc_type, exc_value, tb)
Aug 29 13:43:14 vps578947 gunicorn3[6740]: File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 35, in reraise
Aug 29 13:43:14 vps578947 gunicorn3[6740]: raise value
Aug 29 13:43:14 vps578947 gunicorn3[6740]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1813, in full_dispatch_request
Aug 29 13:43:14 vps578947 gunicorn3[6740]: rv = self.dispatch_request()
Aug 29 13:43:14 vps578947 gunicorn3[6740]: File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1799, in dispatch_request
Aug 29 13:43:14 vps578947 gunicorn3[6740]: return self.view_functions[rule.endpoint](**req.view_args)
Aug 29 13:43:14 vps578947 gunicorn3[6740]: File "/var/www/cards-against-humanity/app/routes.py", line 225, in game
Aug 29 13:43:14 vps578947 gunicorn3[6740]: request.args.get('id')
Aug 29 13:43:14 vps578947 gunicorn3[6740]: File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/orm/query.py", line 923, in get
Aug 29 13:43:14 vps578947 gunicorn3[6740]: ident, loading.load_on_pk_identity)
Aug 29 13:43:14 vps578947 gunicorn3[6740]: File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/orm/query.py", line 984, in _get_impl
Aug 29 13:43:14 vps578947 gunicorn3[6740]: if len(primary_key_identity) != len(mapper.primary_key):
Aug 29 13:43:14 vps578947 gunicorn3[6740]: TypeError: object of type 'NoneType' has no len()