我有一个在Ubuntu 18.04,nginx上运行的Laravel应用。
我有一些默认的服务器配置,并尝试添加从非www到www版本的重定向。为@
和www.
设置了A记录
我尝试在第48行的return语句中添加www.
,但无济于事。
server {
root /var/www/domain/public;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name domain.co.uk;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain.co.uk/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.co.uk/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = domain.co.uk) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name domain.co.uk;
return 404; # managed by Certbot
}
我需要它始终重定向到https://www.domain.co.uk,无论用户是否使用www
以及是否使用https
来访问它