![http3 从所有链接中删除域名](https://linux22.com/image/783618/http3%20%E4%BB%8E%E6%89%80%E6%9C%89%E9%93%BE%E6%8E%A5%E4%B8%AD%E5%88%A0%E9%99%A4%E5%9F%9F%E5%90%8D.png)
几天前,我安装了 NGINX 1.23.3 QUIC 和 Brotli、TLS 1.3、OpenSSL 1.1.1s,以及 HTTP/2 和 HTTP/3……因此服务器带有 fastcgi 和 php-fpm……当我第一次加载网站时,它可以使用 http2,一切正常。重新加载页面后,或者我访问网站上的某些文章或类别后,链接中不再有 domain.com……例如 https://example.com/somecat/subcat... 使用 http3 时是 https://somecat/subcat... 我花了很多时间试图找到问题,但一无所获,甚至想不出在哪里可以找到。
我只发现,如果我在 location / { 后放置 proxy_pass http://example.com;,它只会修复主页的问题,而不会修复整个网站(类别……等等)。也许有人遇到过这种问题……任何建议都很好!!!
主机配置如下:
server {
listen IP:443 http3;
listen IP:443 ssl http2;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
ssl_certificate /home/admin/conf/web/ssl.example.com.pem;
ssl_certificate_key /home/admin/conf/web/ssl.example.com.key;
}
server {
listen IP:443 http3 reuseport;
listen IP:443 ssl http2;
server_name example.com;
root /home/admin/web/example.com/public_html;
index index.php index.html index.htm;
#access_log /var/log/nginx/domains/example.com.log combined;
#access_log /var/log/nginx/domains/example.com.bytes bytes;
access_log off;
error_log /var/log/nginx/domains/example.com.error.log error;
ssl_protocols TLSv1.2 TLSv1.3;
quic_retry on;
ssl_early_data on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:ECDHE:!COMPLEMENTOFDEFAULT;
#ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4;
ssl_ecdh_curve X25519:prime256v1:secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_prefer_server_ciphers off;
ssl_session_tickets off;
ssl_buffer_size 8k;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
ssl_trusted_certificate /etc/pki/tls/certs/ca-bundle.crt;
ssl_certificate /home/admin/conf/web/ssl.example.com.pem;
ssl_certificate_key /home/admin/conf/web/ssl.example.com.key;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
http2_push_preload on;
add_header Alt-Svc 'h3=":443"; ma=86400, h3-29=":443"; ma=86400';
add_header QUIC-Status $http3;
include /etc/nginx/badbots.conf;
location / {
rewrite "^/pm(/(.*))?/?$" /index.php?do=pm last;
rewrite "^/friends/([^/]*)(/?)+$" /index.php?do=friends&user=$1 last;
rewrite "^/friends/([^/]*)/page/([0-9]+)(/?)+$" /index.php?do=friends&user=$1&cstart=$2 last;
rewrite "^/friends/([^/]*)/common(/?)+$" /index.php?do=friends&subaction=common&user=$1 last;
rewrite "^/friends/([^/]*)/common/page/([0-9]+)(/?)+$" /index.php?do=friends&subaction=common&user=$1&cstart=$2 last;
rewrite "^/friends/([^/]*)/requests(/?)+$" /index.php?do=friends&subaction=requests&user=$1 last;
rewrite "^/friends/([^/]*)/requests/page/([0-9]+)(/?)+$" /index.php?do=friends&subaction=requests&user=$1&cstart=$2 last;
rewrite "^/friends/([^/]*)/suggestions(/?)+$" /index.php?do=friends&subaction=suggestions&user=$1 last;
rewrite "^/page/([0-9]+)(/?)$" /index.php?cstart=$1 last;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page,([0-9]+),([0-9]+),(.*).html$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&cstart=$5&news_name=$6&seourl=$6 last;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page,([0-9]+),(.*).html$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5&seourl=$5 last;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/print:page,([0-9]+),(.*).html$" /index.php?mod=print&subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5&seourl=$5 last;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*).html$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_name=$4&seourl=$4 last;
rewrite "^/([^.]+)/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html$" /index.php?newsid=$4&news_page=$2&cstart=$3&seourl=$5&seocat=$1 last;
rewrite "^/([^.]+)/page,([0-9]+),([0-9]+)-(.*).html$" /index.php?newsid=$3&news_page=$2&seourl=$4&seocat=$1 last;
rewrite "^/([^.]+)/print:page,([0-9]+),([0-9]+)-(.*).html$" /index.php?mod=print&news_page=$2&newsid=$3&seourl=$4&seocat=$1 last;
rewrite "^/([^.]+)/([0-9]+)-(.*).html$" /index.php?newsid=$2&seourl=$3&seocat=$1 last;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js|woff|woff2|webp)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php-example.com.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location /error/ {
alias /home/admin/web/example.com/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
location /vstats/ {
alias /home/admin/web/example.com/stats/;
include /home/admin/conf/web/example.com.auth*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
include /home/admin/conf/web/snginx.example.com.conf*;
location ~ "/uploads/.*\.php$|/templates/.*\.php$|/language/.*\.php$|/images/.*\.php$"
{
return 403;
}
location ~* (uploads|uploads/fotos|templates|language)/.+\.php {
deny all;
}
location ~* /templates/.+\.tpl {
deny all;
}
location ~* (engine/cache|engine/data) {
deny all;
}
location ~ /\.ht {
deny all;
}
}
Nginx 配置:
# Server globals
user nginx;
worker_processes auto;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log crit;
pid /var/run/nginx.pid;
# Worker config
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
# Main settings
sendfile on;
#tcp_nopush on;
#tcp_nodelay on;
client_header_timeout 1m;
client_body_timeout 1m;
client_header_buffer_size 2k;
client_body_buffer_size 256k;
client_max_body_size 256m;
large_client_header_buffers 4 8k;
send_timeout 30;
keepalive_timeout 60 60;
reset_timedout_connection on;
server_tokens off;
server_name_in_redirect off;
types_hash_max_size 2048;
variables_hash_max_size 1024;
variables_hash_bucket_size 128;
# Log format
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format bytes '$body_bytes_sent';
#access_log /var/log/nginx/access.log main;
access_log off;
# Mime settings
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Compression
gzip on;
gzip_vary on;
gzip_comp_level 6;
gzip_min_length 512;
gzip_buffers 8 64k;
gzip_proxied any;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/css text/javascript text/js text/xml application/json application/javascript application/x-javascript application/xml application/xml+rss application/x-font-ttf image/svg+xml font/opentype text/x-component text/x-cross-domain-policy;
# Proxy settings
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;
proxy_pass_header Set-Cookie;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
# SSL PCI Compliance
ssl_protocols TLSv1.2 TLSv1.3;
ssl_session_cache shared:SSL:10m;
ssl_ciphers TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:ECDHE:!COMPLEMENTOFDEFAULT;
# Error pages
error_page 403 /error/403.html;
error_page 404 /error/404.html;
error_page 502 503 504 /error/50x.html;
# Cache settings
proxy_cache_path /var/cache/nginx levels=2 keys_zone=cache:10m inactive=60m max_size=1024m;
proxy_cache_key "$host$request_uri $cookie_user";
proxy_temp_path /var/cache/nginx/temp;
proxy_ignore_headers Expires Cache-Control;
proxy_cache_use_stale error timeout invalid_header http_502;
proxy_cache_valid any 1d;
# FastCgi Cache
fastcgi_buffers 8 256k;
fastcgi_buffer_size 256k;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_cache_path /tmp/nginx_cache levels=1:2 keys_zone=fastcgicache:10m max_size=1024m inactive=1h;
# File cache settings
open_file_cache max=10000 inactive=30s;
open_file_cache_valid 60s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
# Wildcard include
include /etc/nginx/conf.d/*.conf;
}
答案1
问题解决了。
保存了包含内容的文件...注意到在加载 http3 时 HTTP_HOST 消失了,分别将其添加到主机 fastcgi_param HTTP_HOST example.com; 一切都按预期运行!像大象一样快乐)))
ps 加载 http3 'HTTP_CACHE_CONTROL' => 'max-age=0' 时这一行有多正确???
答案2
存在已知的向后兼容性问题nginx-quic
:https://github.com/nginx-quic/nginx-quic/issues/3
对我来说我正在使用
fastcgi_param HTTP_HOST $host;
允许 php 服务器从中获取有效主机:authority
伪标头,并替换所有使用$http_host
和$host
在 nginx 配置文件中:https://github.com/vstoykovbg/nginx.conf-examples/pull/2