我正在设置http2
. nginx
下面的代码片段是我在sites-available
目录中的 nginx 虚拟主机:
upstream mysite {
server unix:/home/user/myproject/mysite.sock fail_timeout=0;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2;
server_name www.mysite.com;
ssl on;
ssl_certificate /etc/nginx/ssl/mysite.com.chained.crt;
ssl_certificate_key /etc/nginx/ssl/mysite.com.key;
client_max_body_size 4G;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/user/myproject;
expires 1d;
}
# access_log /opt/simple_academy/logs/nginx-access.log;
# error_log /opt/simple_academy/logs/nginx-error.log;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https; # <-
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://mysite;
break;
}
}
}
nginx 在这里是反向代理,主要的网络服务器是Gunicorn
用于服务Django
代码的。当我使用 Chrome 或 Firefox 检查元素测试该站点时,它会将所有连接协议显示为HTTP1.1
. 我该如何解决这个问题?
更新
以下是nginx -V
命令的结果:
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf -- error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --锁定路径=/var/run/nginx。锁定 --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/ var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx -- group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module--with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt= '-Wl,-z,relro -Wl,-z,now -Wl,--按需 -pie'