1. 安装包下载地址

链接:http://nginx.org/download/nginx-1.15.9.tar.gz

2. 安装Nginx相关组件

  • 安装c++编译环境
[[email protected] ~]# yum install -y gcc-c++
  • 安装pcre
[[email protected] ~]# yum install -y pcre pcre-devel
  • 安装zlib
[[email protected] ~]# yum install -y zlib zlib-devel
  • 安装openssl
[[email protected] ~]# yum install -y openssl openssl-devel
  • 或者全部一起安装
[[email protected] ~]# yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

3.Nginx安装

  • 安装包位置在/usr/lcoal/java路径下

  • 解压:(解压到/usr/local/java路径下)

[[email protected] ~]# tar zxvf /usr/local/java/nginx-1.15.9.tar.gz -C /usr/local/java
  • 需要先创建安装目录(usr/local/java/nginx)
[[email protected] ~]# mkdir /usr/local/java/nginx
  • 进入到解压目录
[[email protected] ~]# cd /usr/local/java/nginx-1.15.9
  • 指定安装目录(/usr/local/java/nginx) 以及 安装的相关模块(这里面的模块已经包括了ssl的模块,nginx配置https需要)
[[email protected] nginx-1.15.9]#  /usr/local/java/nginx-1.15.9/configure --prefix=/usr/local/java/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
  • 指定成功
Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/java/nginx"
  nginx binary file: "/usr/local/java/nginx/sbin/nginx"
  nginx modules path: "/usr/local/java/nginx/modules"
  nginx configuration prefix: "/usr/local/java/nginx/conf"
  nginx configuration file: "/usr/local/java/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/java/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/java/nginx/logs/error.log"
  nginx http access log file: "/usr/local/java/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_temp"
  nginx http scgi temporary files: "scgi_temp"

[[email protected] nginx-1.15.9]#
  • 编译
[[email protected] nginx-1.15.9]# make
  • 编译完成
前面省略.....
前面省略.....
-ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/java/nginx|" \
	-e "s|%%PID_PATH%%|/usr/local/java/nginx/logs/nginx.pid|" \
	-e "s|%%CONF_PATH%%|/usr/local/java/nginx/conf/nginx.conf|" \
	-e "s|%%ERROR_LOG_PATH%%|/usr/local/java/nginx/logs/error.log|" \
	< man/nginx.8 > objs/nginx.8
make[1]: 离开目录“/usr/local/java/nginx-1.15.9”
[[email protected] nginx-1.15.9]# 
  • 安装
[[email protected] nginx-1.15.9]# make install
  • 安装完成
make[1]: 进入目录“/usr/local/java/nginx-1.15.9”
中间省略.....
make[1]: 离开目录“/usr/local/java/nginx-1.15.9”
[[email protected] nginx-1.15.9]# 
  • 安装目录图片
    Linux-CentOS7-系统安装部署Nginx

4. 启动、停止

  • 进入nginx安装目录
[[email protected] nginx-1.15.9]# cd /usr/local/java/nginx/
[[email protected] nginx]#
  • 启动(并指定配置文件)
[[email protected] nginx]# ./sbin/nginx
[[email protected] nginx]#
  • 启动成功(存在启动进程)
[[email protected] nginx]# ps -ef | grep nginx
root      26003      1  0 11:41 ?        00:00:00 nginx: master process ./sbin/nginx
nobody    26004  26003  0 11:41 ?        00:00:00 nginx: worker process
root      26006  22005  0 11:42 pts/0    00:00:00 grep --color=auto nginx
[[email protected] nginx]# 
  • 停止
[[email protected] nginx]# ./sbin/nginx -s stop
[[email protected] nginx]# 
  • 停止成功(进程已经不在了)
[[email protected] nginx]# ps -ef | grep nginx
root      26024  22005  0 12:28 pts/0    00:00:00 grep --color=auto nginx
[[email protected] nginx]# 

5. 浏览器访问

  • 查看nginx配置文件端口
[[email protected] nginx]# cat ./conf/nginx.conf

Linux-CentOS7-系统安装部署Nginx

  • 关闭防火墙或者打通指定端口(关闭防火墙或者打通端口,浏览器才能访问)

    • 关闭防火墙
      • 查看防火墙状态(我这是关闭的 inactive (dead) 这个表示关闭)
      [[email protected] nginx]# systemctl status firewalld
      ● firewalld.service - firewalld - dynamic firewall daemon
           Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
           Active: inactive (dead) since 一 2019-03-25 16:31:37 CST; 20h ago
             Docs: man:firewalld(1)
          Process: 20935 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
         Main PID: 20935 (code=exited, status=0/SUCCESS)
         
      3月 25 16:29:53 aubin.com systemd[1]: Starting firewalld - dynamic firewall daemon...
      3月 25 16:29:54 aubin.com systemd[1]: Started firewalld - dynamic firewall daemon.
      3月 25 16:31:35 aubin.com systemd[1]: Stopping firewalld - dynamic firewall daemon...
      3月 25 16:31:37 aubin.com systemd[1]: Stopped firewalld - dynamic firewall daemon.
      [[email protected] nginx]# 
      
      • 开启防火墙(并查看状态 active (running) 表示防火墙开启的)
      [[email protected] nginx]# systemctl start firewalld
      [[email protected] nginx]# systemctl status firewalld
      ● firewalld.service - firewalld - dynamic firewall daemon
           Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
           Active: active (running) since 二 2019-03-26 13:00:19 CST; 1min 5s ago
             Docs: man:firewalld(1)
         Main PID: 26048 (firewalld)
           CGroup: /system.slice/firewalld.service
                   └─26048 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
         
      3月 26 13:00:18 aubin.com systemd[1]: Starting firewalld - dynamic firewall daemon...
      3月 26 13:00:19 aubin.com systemd[1]: Started firewalld - dynamic firewall daemon.
      [[email protected] nginx]#
      
      • 关闭防火墙(并查看状态 inactive (dead))
      [[email protected] nginx]# systemctl stop firewalld
      [[email protected] nginx]# systemctl status firewalld
      ● firewalld.service - firewalld - dynamic firewall daemon
           Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
           Active: inactive (dead) since 二 2019-03-26 13:03:22 CST; 2s ago
             Docs: man:firewalld(1)
       Process: 26048 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
      Main PID: 26048 (code=exited, status=0/SUCCESS)
      
      3月 26 13:00:18 aubin.com systemd[1]: Starting firewalld - dynamic firewall daemon...
      3月 26 13:00:19 aubin.com systemd[1]: Started firewalld - dynamic firewall daemon.
      3月 26 13:03:21 aubin.com systemd[1]: Stopping firewalld - dynamic firewall daemon...
      3月 26 13:03:22 aubin.com systemd[1]: Stopped firewalld - dynamic firewall daemon.
      
    • 放开80端口
      • 查看端口80是否放开 (telnet ip port 格式)–如下面结果代表没放开
      [[email protected] nginx]# telnet 192.168.1.44 80 
      Trying 192.168.1.44...
      telnet: connect to address 192.168.1.44: Connection refused
      [[email protected] nginx]#
      
      • 放开端口(如下表示成功)
      [[email protected] nginx]# firewall-cmd --zone=public --add-port=80/tcp --permanent
      success
      [[email protected] nginx]# 
      
      • 关闭端口命令(如下表示成功)
      [[email protected] nginx]# firewall-cmd --zone=public --remove-port=80/tcp --permanent
      success
      [[email protected] nginx]# 
      
  • 访问界面(需关闭防火墙,或者开启nginx端口可访问)界面如下
    Linux-CentOS7-系统安装部署Nginx

相关文章: