首页 > 解决方案 > 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,但它显示“无法连接” 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模式

我究竟做错了什么?

标签: linuxubuntunginx

解决方案


添加 localhost 作为服务器名称并尝试使用它访问您的应用程序。

确保根属性指向文件夹而不是文件,并在末尾添加 /。

还要确认您的 PHP 安装工作正常。


推荐阅读