这是我的 NGinx Web 服务器配置
server {
if ($host ~ ^[^.]+\.betafox\.net$) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = www.betafox.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = betafox.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
#server_name _;
root /var/www/html;
server_name betafox.net *.betafox.net;
#return 301 https://$host$request_uri;
index index.php index.html index.htm;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
proxy_pass https://betafox.net/;
proxy_redirect https://betafox.net/ $host;
proxy_set_header Accept-Encoding "";
proxy_ssl_server_name on;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/run/php/php8.0-fpm.sock;
fastcgi_pass unix:/etc/alternatives/php-fpm.sock;
}
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
root /var/www/html;
index index.php index.html index.htm;
# server_name _;
server_name betafox.net *.betafox.net;
# Maximum file upload size is 4MB - change accordingly if needed
client_max_body_size 512M;
client_body_buffer_size 128k;
include snippets/letsencrypt-nginx-certs.conf;
include snippets/letsencrypt-nginx-route.conf;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php8.0-fpm.sock;
fastcgi_pass unix:/etc/alternatives/php-fpm.sock;
}
ssl_certificate /etc/letsencrypt/live/betafox.net-0001/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/betafox.net-0001/privkey.pem; # managed by Certbot
}
当我为我的 FQDN 和子域安装 SSL 证书时,Certbot 自动修改了大部分内容。我面临的问题是关于 URL 重定向。原始 URL 是www.betafox.net,当用户键入 betafox.net 时,将重定向到https://betafoxnet.www.betafox.net/并且有消息说:您要查找的站点不存在。
我只希望所有键入 betafox.net 的用户都被转发到www.betafox.net。我相信 Nginx 可以做到这一点。我怎样才能做到这一点?