Nginx 服务运行成功但返回 apache 默认页面?

Nginx 服务运行成功但返回 apache 默认页面?

我在已经有 apache2 的服务器(ubuntu 16.04)上安装了 nginx,并完成了以下配置,

->将 apache 端口 80 更改为 8888,以便 nginx 将监听 80
->按顺序重新启动 apache 和 nginx。

当我输入时仍然显示 apache 默认页面http://本地主机 我还停止了 apache2 服务并重新启动了 nginx 服务以确保服务器每次只运行一次,但在 localhost 请求时仍然会获取 apache 默认页面!!!这实际上应该是 nginx 默认页面,因为 apache 服务不再运行。

我发现可疑的一件事是“htcacheclean”进程正在运行,它负责返回 Apache 页面吗?!

对我来说,这种情况发生得很奇怪!!如果您遇到过此类问题,请分享提示。

ss -tlnp 返回端口 80 的以下内容
State Recv-Q Send-Q 本地地址:端口 对等地址:端口
LISTEN 0 0 *:80 **:* *

ss -tlnp | grep nginx 命令输出显示 nginx

ss -tlnp | grep nginx 命令输出

答案1

这是因为 nginx 可能有相同的文档根目录作为 apache 并且它的 index.html 仍然在 中/var/www/html。我遇到了同样的问题。

答案2

在我的 Linux 中遇到了同样的问题。解决方案是完全清除 apache2。对我来说,命令是 -sudo apt purge apache2

这是问题的完整解决方案-

  1. 使用 gunicorn 启动你的 django 网站
  2. 编辑 nginx 配置以告诉它监听除端口 80 之外的其他端口

3.Boom解决了。(别忘了重启nginx)

操作方法如下-(我的 django 站点名称是“mysite”;将其替换为您的(包含文件的文件夹wsgi)。)

  1. 在你的 django 站点文件夹命令中:gunicorn mysite.wsgi:application
  2. 编辑 nginx - 命令:sudo nano /etc/nginx/sites-available/mysite_nginx.conf 使用代码:-

server { listen 8001; server_name 192.168.1.36; # 你的机器的本地 IP 地址

location / {
    proxy_pass http://127.0.0.1:8000;  # Gunicorn's default bind address
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

然后,为其创建一个符号链接-命令:sudo ln -s /etc/nginx/sites-available/mysite_nginx.conf /etc/nginx/sites-enabled

3.重新启动nginx服务-命令:sudo service nginx restart 或命令:sudo /etc/init.d/nginx start

最后,它将可供连接到本地网络的每个设备使用“http://your_machine_ip:8001”来访问它

请原谅我初学者犯的愚蠢错误;我对此还很陌生。

相关内容