CentOS7配置Nginx默认首页过程解析

找到nginx的安装目录:

whereis nginx

在这里插入图片描述


进入nginx/html目录:

cd /usr/local/nginx/html/

在这里插入图片描述


进入nginx/conf目录:

cd ..
cd conf

在这里插入图片描述


查看nginx.conf (nginx的核心配置文件):

vim nginx.conf
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
  worker_connections  1024;
}


http {
  include       mime.types;
  default_type  application/octet-stream;

  #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  #                  '$status $body_bytes_sent "$http_referer" '
  #                  '"$http_user_agent" "$http_x_forwarded_for"';

  #access_log  logs/access.log  main;

  sendfile        on;
  #tcp_nopush     on;

  #keepalive_timeout  0;
  keepalive_timeout  65;

  #gzip  on;

  server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
      root   html;
      index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
  }

  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
  #    proxy_pass   http://127.0.0.1;
   #}

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

查看其中的server:

server {
    listen       80;
    server_name  localhost;
    
    location / {
      root   html;
      index  index.html index.htm;
    }
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
  }

● listen:待监听的端口号;
● server_name:请求时的IP,如果在域名系统中进行了DNS解析(已经将IP和域名进行了映射),也可以直接使用域名来进行访问;
● location:映射。

location / {
  root   html;
  index  index.html index.htm;
}

○ / :找到根目录,也就是下面的root;
○ html:相对文件夹的位置(相对的是和conf目录在同一级目录);
○ index index.html index.htm:配置一个默认的首页index.html和index.htm。


修改当前.conf文件的listen值为88:

server {
    listen       88;
    server_name  localhost;
    
    location / {
      root   html;
      index  index.html index.htm;
    }
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
  }

保存文件,进入 nginx/sbin 目录
在这里插入图片描述


重新加载配置文件:

./nginx -s reload

浏览器访问:

http://[ip地址]:88

在这里插入图片描述




注:如果是在云服务器上操作,在访问之前需要确认新修改的这个端口,是否已在安全组中进行开放。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值