我有一个在AWS EC2 Ubuntu(ngnix)上托管的Laravel 9项目。该域名在GoDaddy注册,我更改了A记录,将其指向AWS EC2的IP。当我使用www.example.com之类的url时,我的网站运行良好example.ca,但是,当我使用url**www.example.ca时,它就不工作了(我得到了默认的欢迎来到nginx!**页面)
根据Google搜索,我在public/.htaccess中添加了以下重写规则
RewriteCond %{HTTP_HOST} ^www.example.ca [NC]
RewriteRule ^(.*)$ http://example.ca/$1 [L,R=301]
然而,这并没有帮助。我仍然继续获得默认的Nginx页面。
还有什么需要我做的吗?例如,在sites-enabled中。我想补充的是,当我设置我的项目时,我在**/etc/nginx/sites-available**文件夹中创建了一个新文件,其中包含以下内容
server {
listen 80;
listen [::]:80;
server_name example.ca;
root /var/www/vhosts/example.ca/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
任何帮助都是非常感谢的。
1条答案
按热度按时间knsnq2tg1#
将**服务器名称example.ca;更改为服务器名称example.ca www.example.ca;**修复了此问题。(感谢Andrew St-Denis。)