Nginx知识点和部署

Nginx部署

介绍
Nginx就是反向代理服务器。
代理服务器一般是指局域网内部的机器通过代理服务发送请求到互联网上的服务器,代理服务器一般作用于客户端。
代理服务器是介于客户端和Web服务器之间的另一台服务器,有了它之后,浏览器不是直接到Web服务器去取回网页,而是通过向代理服务器发送请求,信号会先送到代理服务器,由代理服务器来取回浏览器所需要的信息并传送给你的浏览器。
正向代理是一个位于客户端和原始服务器之间的服务器,为了从原始服务器取的内容,客户端向代理发送一个请求并指定目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返回给客户端,客户端必须要进行一些特别的设置才能使用正向代理。
反向代理服务器:在服务器端接收客户端的请求,然后把请求分发给具体的服务器进行处理,然后再将服务器的响应结果反馈给客户端。Nginx就是其中的一种反向代理服务器软件。
具体内容可以参照:https://www.cnblogs.com/muhy/p/10528543.html(谢谢大佬提供的详解)

要求:
1、 节点
IP 主机名 节点
192.168.200.11 nginx Nginx 节点

2、使用本地 PC 环境的 VMWare Workstation 软件进行实操练习,镜像使用提供的
CentOS-7-x86_64-DVD-1511.iso。虚拟机配置为 1 核/2G 内存/20G 硬盘。
步骤
1、 修改主机名

[root@localhost ~]# hostnamectl set-hostname nginx 
[root@localhost ~]# logout 
[root@nginx ~]# hostnamectl  
   Static hostname: nginx 
         Icon name: computer-vm 
           Chassis: vm 
        Machine ID: 179f6c8f2e7942ef81b0f5565a6883fa 
           Boot ID: 9ac638fec1c64c94aab96d0acfa4f542 
    Virtualization: vmware 
  Operating System: CentOS Linux 7 (Core) 
       CPE OS Name: cpe:/o:centos:centos:7 
            Kernel: Linux 3.10.0-327.el7.x86_64 
      Architecture: x86-64

(2)关闭防火墙及 SELinux 服务
关闭防火墙 firewalld 及 SELinux 服务,命令如下

[root@nginx ~]# setenforce 0
[root@nginx ~]# systemctl stop firewalld

(3)安装配置基础服务
配置本地 YUM 源,编译安装基础环境,命令如下:

[root@nginx ~]# yum install gcc gcc-c++ openssl-devel zlib-devel zlib pcre-devel –y 

创建指定用户,这个 nginx 用户要和 PHP 服务器上创建的 nginx 两者 id 一致,这里先
创建用户,命令如下:

[root@nginx ~]# groupadd -g 1001 nginx
[root@nginx ~]# useradd -u 900 nginx -g nginx -s /sbin/nologin
[root@nginx ~]# tail -1 /etc/passwd
nginx:x:900:1001::/home/nginx:/sbin/nologin

(4)安装配置 Nginx 服务

[root@nginx ~]# cd /usr/local/src/
[root@nginx src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz

解压缩:

[root@nginx src]# tar -zxvf nginx-1.12.2.tar.gz

进入nginx-1.12.2/目录下进行编译:

[root@nginx src]# cd nginx-1.12.2/
[root@nginx nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_dav_module \
> --with-http_stub_status_module --with-http_addition_module \
> --with-http_sub_module --with-http_flv_module --with-http_mp4_module \
> --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx
[root@nginx nginx-1.12.2]# echo $?
0

安装

[root@nginx-1.12.2]# make && make install

编译安装完毕后,创建软连接并启动测试,命令如下:(netstat 命令无法使用时,请自
行使用 YUM 源安装 net-tools 工具)

[root@nginx nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@nginx nginx-1.12.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx nginx-1.12.2]# nginx
[root@nginx nginx-1.12.2]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      3315/mysqld         
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      802/rpcbind         
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6950/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1413/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1997/master         
tcp6       0      0 :::111                  :::*                    LISTEN      802/rpcbind         
tcp6       0      0 :::22                   :::*                    LISTEN      1413/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1997/master 

发现端口80,表示nginx服务启动成功。可以在浏览器访问地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值