第10篇 nginx部署出现 Welcome to nginx! If you see this page 该如何解决

当你部署nginx的时候出现,ping域名网站可以通,但是访问不了网站怎么办,不用急,往下看;

1.问题所在

image

其实出现以上的问题就代表你已经成功搭建好了nginx,只是现在默认访问的时候跳转到了nginx的首页问题。

2.解决方案

默认情况下,Nginx 安装后会使用默认配置文件,这些文件通常会指向一个默认的欢迎页面
为了让 Nginx 指向网站内容,需要修改默认配置
找到Nginx的配置文件,nginx.conf指向网站目录

server {
listen 80;
server_name your_domain.com;

location / {
root /var/www/your_website;
index index.html index.htm;
}
}

注释掉或者删除默认欢迎的页面配置
include /etc/nginx/conf.d/.conf;
include /etc/nginx/sites-enabled/
;

然后刷新配置文件【记住,每次修改配置文件后都得,先检查刷新】
sudo nginx -t:检查配置文件并且进行重启
使用命令 sudo systemctl reload nginx 或 sudo nginx -s reload 重新加载 Nginx 配置

还有检查是否DNS有问题:建议设置成114.114.114.114或者8.8.8.8 尝试是否可以登录

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;

Logging settings

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

Gzip settings

gzip on;
gzip_disable "msie6";
}

server {
listen 80;
server_name your_domain.com;

location / {
root /var/www/your_website;
index index.html index.htm;
}

location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires max;
log_not_found off;
}
}

3.思路

出现这样的问题一般先想到网站是否能ping 通,网站DNS解析有没有成功,配置文件有没有正确配置重定向文件

posted @ 2024-08-27 21:42  似梦亦非梦  阅读(4848)  评论(0)    收藏  举报