nginx 安装配置和常用命令

基本环境:CentOS

1. 下载 nginx

[root@localhost ~]# cd Downloads/
[root@localhost Downloads]# wget http://nginx.org/download/nginx-1.13.6.tar.gz

2. 安装 nginx 依赖

yum -y install openssl openssl-devel
yum -y install pcre-devel

3. 编译安装

将 nginx 安装在 /opt/nginx 目录下

[root@localhost Downloads]# tar -xvf nginx-1.13.6.tar.gz 
[root@localhost  Downloads]# mkdir -p /opt/nginx
[root@localhost Downloads]# cd nginx-1.13.6/
[root@localhost nginx-1.13.6]# ./configure --prefix=/opt/nginx
[root@localhost nginx-1.13.6]#  make && make install

4. nginx 基本命令

检查 nginx 配置语法是否正确

[root@localhost ~]# /opt/nginx/sbin/nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful

启动 nginx

/opt/nginx/sbin/nginx

重新加载 nginx 配置

[root@localhost ~]# /opt/nginx/sbin/nginx -s reload

nginx 帮助

[root@localhost ~]# /opt/nginx/sbin/nginx -h
nginx version: nginx/1.13.6
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /opt/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file
原文地址:https://www.cnblogs.com/reycg-blog/p/7852236.html