centos7安装ngnix

centos7安装ngnix

1. 安装基础命令

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2. 下载ngnix

wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure
make
make install
Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_tem

3. 配置ngnix

1. 加入到环境变量

vim /etc/profile
# 在文件末尾追加
export NGNIX_HOME=/usr/local/nginx
export PATH=$PATH:$NGNIX_HOME/sbin
# 重新加载profile
source /etc/profile

2. 防火墙配置

nginx默认监听80端口,如果未关闭防火墙需要配置iptables规则开放80端口(以centos6为例)。
编辑配置文件:

vim /etc/sysconfig/iptables
# 在文件中间添加iptables规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# 重启防火墙:
service iptables restart
# 或者关闭iptables规则
iptables -F && iptables -t nat -F

3. Nginx验证

nginx主配置文件:/usr/local/nginx/conf/nginx.conf
nginx日志文件:/usr/local/nginx/logs/access.log
启动Nginx:/usr/local/nginx/sbin/nginx
然后直接访问ip地址,比如:http://192.168.0.254/,如果能看到如下Nginx主页说明安装ok。

4. Nginx常用命令

${Nginx} = /usr/local/nginx

测试配置文件:${Nginx}/sbin/nginx -t
启动命令:${Nginx}/sbin/nginx
停止命令:${Nginx}/sbin/nginx -s stop/quit
重启命令:${Nginx}/sbin/nginx -s reload
查看进程命令:ps -ef | grep nginx
平滑重启:kill -HUP [Nginx主进程号(即ps命令查到的PID)]

# 重新载入配置文件
nginx -s reload
# 重启 Nginx
nginx -s reopen 
# 停止 Nginx
nginx -s stop              

你可能感兴趣的:(运维)