转到域列表

2024-09-21 00:58:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在开发一个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()

Tags: inhttpshttpserverrequestaugproxyheader

热门问题