linux - nginx(example.app)中的自定义域无法连接
问题描述
在 LEMP 堆栈的主题下,我们的任务是创建/配置一个名为“thething.app”的网站
与此处提供的指南一样,我按照步骤 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
我测试了导致成功的语法,然后我重新启动了 nginxsudo systemctl reload nginx
然后我尝试在浏览器上访问 thething.app,但它显示“无法连接”
幸运的是我发现了这个:Setting 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 安装工作正常。
推荐阅读
- spring-boot - Spring Security:表单登录无法正常工作
- format - 是否可以调整 Google Data Studio 中标签的位置?
- groovy - 从文本中读取特定字符串
- excel - 用于填充书签并保存少量 PDF 文件的宏
- next.js - 如何在 next.js 中正确配置外部图像加载器?
- php - 如何使用 PHP implode 函数通过一条 INSERT 语句将多行插入 mysql?
- sql - 运行求和查询
- android-studio - 如何防止底部栏导航在android studio过渡期间移动?
- aws-glue - 从 VPC 将 Glue 连接到 RDS、S3 和 Secrets Manager
- kubeflow - 无法提取图像“gcr.io/google-containers/busybox”