在 LEMP 堆栈的主题下,我们的任务是创建/配置一个名为“thething.app”的网站
与 here 提供的指南一样,我按照第4步的配置部分。
唯一的区别是该站点将在 web 目录中有一个 php 文件而不是一个 html
<?php
echo "this is thething.app";
?>
这是我的(原始)配置:server {
listen 80;
server_name thething.app www.thething.app;
root /home/melonpan/thething.app;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
通过链接到 Nginx 启用站点的目录中的配置文件激活我的配置后 sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
我用 sudo nginx -t
测试了语法这导致成功,然后我用 sudo systemctl reload nginx
重新启动了 nginx然后我尝试在浏览器上访问 thething.app,但它显示“无法连接”
幸运的是我发现了这个:Setting up nginx to support custom domain name
有类似的问题。
所以我删除了
server_name
行使我的新配置成为server {
listen 80;
root /home/melonpan/thething.app;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
在重新链接、测试和重新启动 nginx 之后,我认为它会起作用。 但不是!它仍然无法连接。 我什至编辑了主机文件
sudo nano /etc/hosts
并添加了 127.0.1.1 thething.app
我们正在使用 ubuntu编辑:我试过 http://thething.app同样,在 Firefox 中禁用 http only 模式的事件
我究竟做错了什么?
最佳答案
添加 localhost 作为服务器名称并尝试使用它访问您的应用程序。
确保根属性指向文件夹而不是文件,并在末尾添加/。
还要确认您的 PHP 安装工作正常。
关于linux - nginx(example.app)中的自定义域无法连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69963678/