Nginx 服务器源码安装配置流程

网络服务器对比---- ----了解

大公司开发的网络软件例如:【淘宝】

Unix和Linux的的平台下

- Apache从有网络开始fdskkbew开发自己就有它。

     Nginx [并发高,小,速度快]

     Lighttped

--Tomca IBM WebSphere Jboos(用在jiv上的服务器)

Windows平台下 - 微软公司的IIS(Internet Information Server)

 

Nginx的简介

俄罗斯人编写的十分轻量级的HTTP服务器,高性能的HTTP和反向代理服务器,同时也是一个IMAP / POP3 / SMTP代理服务器。

官方网站:http//nginx.org/

配置文件级目录

安装目录:/ usr / local / nginx /

主配置文件:conf / nginx.conf

网页目录:HTML

日志文件:日志

启动脚本:sbin / nginx

 

启动Nginx的的服务

Sbin / nginx -c conf / nginx.conf

 

[root @ Proxy~] #cd / root / lnmp_soft

[root @ Proxy lnmp_soft] #ls

[root @ Proxy lnmp_soft]#。/ install_lnmp.sh

模块的软件的Nginx的

有100个功能

什么都不选择默认配置20个功能。

Tar -xf nginx

./cnfigure直接回车默认会选择20个功能安装。

./cnfigure --with-xxx启动某个功能

          --without-XXX停用某个功能。

nginx.org此网站有所有的说明,功能,于例题

脚本里加了一个./cnfigure --wit-htp_ssl_module

[root @ Proxy lnmp_soft] #netstat -ntulp | grep 80

tcp6 0 0 ::: 80 ::: * LISTEN 2517 /(squid-1)      

[root @ Proxy lnmp_soft] #nginx

 

 

[root @ Proxy lnmp_soft] #systemctl stop squid

[root @ Proxy lnmp_soft]#/ etc / init.d / varnish start

启动清漆(通过systemctl):^ C.

[root @ Proxy lnmp_soft] #netstat -ntulp | grep 80   

[root @ Proxy lnmp_soft] #killall varnishd

 

 

nginx#启服务

#nginx -V#查看安装方式

每次起服务关服务他会自动做-t测试一下默认配置文件。

nginx -s stop#关闭服务

Nginx -s reload#不启,加载新的配置文件

在vim里

Ctrl + v:连续选择。

 

更新升级

!注意:不要用最后make install:会覆盖原有的内容

柏油

[root @ Proxy lnmp_soft] #cd lnmp_soft

[root @ Proxy lnmp_soft] #rm -rf nginx-1.8.0

[root @ Proxy lnmp_soft] #tar -xf nginx-1.8.0.tar.gz

[root @ Proxy lnmp_soft] #cd nginx-1.8.0

[root @ Proxy nginx-1.8.0] #ls

[root @ Proxy nginx-1.8.0]#。/ configure --with-http_ssl_module

[root @ Proxy nginx-1.8.0] # make#把源码编译成二进制程序。

[root @ Proxy nginx-1.8.0] #ls objs /

Lnmp_soft / nginx的-1.9.0 / OBJ文件/ nginx的

在/ usr /本地/ nginx的/ sbin目录/ nginx的

[root @ Proxy nginx-1.8.0] #cd / usr / local / nginx /

[root @ Proxy nginx] #ls

[root @ Proxy nginx] #cd sbin /

[root @ Proxy sbin] #ls

[root @ Proxy sbin] #mv nginx nginx.old

[root @ Proxy sbin] #cp /root/lnmp_soft/nginx-1.8.0/objs/nginx。

[root @ Proxy sbin] #ls

 

./configure 

时提示以下错误:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

解决方法:

执行以下命令:

yum -y install openssl openssl-devel

执行成功之后再执行

./configure

 

用户认证:

  1. 添加认证配置

[root @ Proxy sbin] #vim /usr/local/nginx/conf/nginx.conf

  服务器{

        听80;

        server_name localhost;

    auth_basic“INPUT PASS:”; #访问网站出来对话框提示文件

auth_basic_user_file“/ usr / local / nginx / pass”;

#修改配置文件第一步告诉他文件名和密码在那在.....

 

 

  1. 生成密码文件:

[root @ Proxy sbin] #yum -y install httpd-tools

[root @ Proxy sbin] #htpasswd -cm / usr / local / nginx / pass tom

[root @ Proxy sbin] #htpasswd -cm / usr / local / nginx / pass tom

 

3.从新启动配置文件。

[root @ Proxy~] #nginx -s reload

查看错误日志:

-cm:创建新用户

-m:不覆盖用户创建其他用户。

[root @ Proxy~] #htpasswd -m / usr / local / nginx / pass lily

[root @ Proxy~] #cat / usr / local / nginx / pass

汤姆:$ APR1 $ 4xD5cdyH $ p52xdcij8lDPkwqwOFsVo0

百合:$ APR1 $ 15L5l / ZG $ 3 / C / q30vXlj1ddGPXN1DC /

 

 

 

 

 

虚拟主机:域名,端口,IP

服务器{

        听80;

        server_name www.a.com;

}

    听80;

        server_name   www.b.com;

}

 

}

注意:服务器不能放在别人的服务器里面

一台服务器用服务器做出两个网页,用IP地址访问最上面的先先出来

[root @ Proxy~] #vim /usr/local/nginx/conf/nginx.conf

 服务器{

        听80; (基于域名访问)或者

        听8000; (基于端口访问)或者

        听192.168.4.5:80; (基于IP访问)

          三选一一般用的是域名和端口

        server_name www.a.com;

    auth_basic“INPUT PASS:”;

    auth_basic_user_file“/ usr / local / nginx / pass”;

 

服务器{

    听80;

    server_name www.b.com;

    位置 /{

           根网;

           index index.html index.htm;

        }

 }

[root @ Proxy~] #cd / usr / local / nginx /

[root @ Proxy nginx] #mkdir web

创建密码echo“1111”> /usr/local/nginx/web/index.html

[root @ Proxy nginx] #nginx -s reload

 在客户机添加:

注意:真实机的火狐关闭

[root @ Client~] #vim / etc / hosts

192.168.4.5 www.a.com  www.b.com

[root@Client ~]# firefox http://www.a.com

[root@Client ~]# firefox http://www.b.com

 

 

 

 

SSL虚拟主机

加密网站HTTPS

http协议是明文协议[apache,nginx,iis]

http+SSL (https)

私钥,公钥

cat /usr/share/dict/

扩展加密算法:

对称算法:AES,DES  () 适用于单机 RAR[加密:对称]

非对称算法:RSA,DSA () 适用于网络

信息 :md5(已经被破解,不安全),sha128,

sha256(数据完整性校验)

 

实验:https非对称算法

  1. 生成私钥和证书

[root@Proxy ~]# cd /usr/local/nginx/conf

[root@Proxy conf]# openssl genrsa > my.key  #生成私钥 

[root@Proxy conf]# openssl req -new -x509  -key my.key  -out my.crt                 

>问的问题:国家、省份、城市、公司名称、部门名称、主机名称、邮箱。

-key my.key   -out my.crt  #用私钥导出证书。

固定格式openssl req -new -x509

 

 

  1. 调用私钥和证书实现网的加密

[root@Proxy conf]# vim /usr/local/nginx/conf/nginx.conf

server {

    listen       443 ssl;

    server_name  www.c.com;

    ssl_certificate      my.crt;

    ssl_certificate_key  my.key;

    location / {

        root   html;

        index  index.html index.htm;

    }

}

}

 

[root@Proxy conf]# nginx  -s reload  #启服务

 

  1. 客户端

#vim /etc/hosts  #修改文件

192.168.4.5  www.a.com  www.b.com  www.c.bom

[root@Client ~]# firefox https://www.c.com

 

 

实验:https非对称算法 两台服务器

创建虚拟机web2:  192.168.2.200  eth1

    LVS『没有健康检查功能』需要写脚本。

                      ----------------web1

            4.5    |               2.100

Ckubet ----nginx------------------------web3  2.50

                    |              2.200

                      ----------------web2

                  拓扑图

  nginx : 不在缓存的调度器

 Nginx :有主动检查的作用,默认算法是论

  调度器 :负载均衡,Web高可用。  

 

[root@web2 ~]# yum -y install httpd

[root@web2 ~]# systemctl start httpd

[root@web2~]#echo "192.168.2.200" > /var/www/html/index.html

[root@web2 ~]# firewall-cmd --set-default-zone=trusted

  1. 先定义集群 (可以添加)

/usr/local/nginx/conf/nginx.conf  #配置文件

[root@Proxy conf]# cp nginx.conf.default nginx.conf

[root@Proxy conf]# vim nginx.conf

 

红需要添加的内容: 

weight=2 :默认是1次权众越高承压越高,访问越多。

ip_hash :相同客户访问相同的服务器(第一次访问定义给1以后在访问是1提供)

max_fails=2 :联系2次联系不上

fail_timeout=30 : 多次联系不上就隔30妙在次联系。

down  : 如果一台服务器多次联系不上就标记为。

   upstream webs{      # 定义集群

    #ip_hash;

    server 192.168.2.100  weight=2 max_fails=1 fail_timeout=30 down;

    server 192.168.2.200;

                             }    

    server {

        listen       80;

        server_name  localhost;

 location / {

            proxy_pass http:// webs;    #调用集群

            root html;

            index index.html index.htm;

        }

 

[root @ Proxy conf] #nginx -s reload

[root @ web1~] #systemctl stop httpd   #关闭一个服务器

[root @ web1~] #systemctl start httpd   #开启服务器

 

用客户端测试:

[root @ Client~] #curl http://192.168.4.5

 

Nginx的用户认证,虚拟主机HTTPS,集群。

 

总结:

正向代理

只用于代理内部网络对互联网的连接请求,客户机必须指定代理服务器,并将本来要直接发送到网站服务器上

猜你喜欢

转载自blog.csdn.net/Rio520/article/details/81143319