Nignx基础操作

Nginx安装&卸载

使用yum安装、卸载nginx:

  1. sudo yum -y install nginx # 安装 nginx
  2. sudo yum remove nginx # 卸载 nginx

安装成功后,默认的网站目录为: /usr/share/nginx/html
默认的配置文件为:/etc/nginx/nginx.conf
自定义配置文件目录为: /etc/nginx/conf.d/

Nginx 及其模块的工作方式在配置文件中确定。默认情况下,配置文件被命名nginx.conf 并放置在目录 /usr/local/nginx/conf、 /etc/nginx或 /usr/local/etc/nginx。

Nginx检查配置

  1. nginx -t

Nginx启动

  1. sudo service nginx start # 启动 nginx 服务
  2. systemctl start nginx

Nginx设置开机启动

  1. sudo systemctl enable nginx # 设置开机启动
  2. systemctl enable nginx # 设置开机启动
  3. systemctl disable nginx # 禁用开机启动

Nginx常用操作

  1. nginx -s stop # fast shutdown 快速关闭
  2. nginx -s quit # graceful shutdown 优雅关闭
  3. nginx -s reload # reloading the configuration file 重新加载配置文件
  4. nginx -s reopen # reopening the log files 重新打开日志文件
  5. sudo service nginx stop # 停止 nginx 服务
  6. sudo service nginx restart # 重启 nginx 服务
  7. sudo service nginx reload # 重新加载配置,一般是在修改过 nginx 配置文件时使用

Nginx查看运行状态

  1. systemctl status nginx

Nginx常用配置