NGINX是轻量级的负载均衡服务器,支持百万级别的访问量,具有良好的稳定性和高并发链接数。


12月2日

软件安装:

下载:http://nginx.org 可以下载最新版本的nginx服务器,下载的文件以压缩文件的形式存在,这里使用源码安装。解压,tar zxvf nginx.......(版本),解压到任意目录,在这里解压到了/tmp文件夹下,解压后的文件如图所示:

nginx安装证书步骤 nginx安装成功_基本配置

开始添加参数,参数设置如下:

nginx安装证书步骤 nginx安装成功_基本配置_02

回车进行安装,安装后会出现以下情况:

nginx安装证书步骤 nginx安装成功_基本配置_03

问题的解决办法是: 

nginx安装证书步骤 nginx安装成功_服务器_04

 然后再次运行以上的配置命令:再次出现了以下的错误:  

nginx安装证书步骤 nginx安装成功_nginx安装证书步骤_05

问题的解决办法:安装相应的软件包  

nginx安装证书步骤 nginx安装成功_负载均衡_06

最后完成所有的软件包的安装:提示安装nginx成功  

nginx安装证书步骤 nginx安装成功_nginx安装证书步骤_07

./configure  出现未找到错误,一般在这种情况下需要安安装以下几个安装包

yum install -y pcre-devel。。。。。。

yum install -y openssl-devel。。。。。。

yum install -y openssl1.0.0 。。。。。。

yum install -y zlib。。。。。。。

安装如上的安装包,显示nginx安装完成,successful

make && make install

nginx -t (这条命令是检查nginx安装是否完成的测试命令)

提示没有安装完成,原因是,1 没有添加用户,2 没有创建相应的用户。

创建之前的配置是写的用户名为nginx        useradd nginx  创建不存在的目录 mkdir 。。。。

启动 nginx            命令   nginx

查看是否启动完成,ps -ef |grep nginx

配置nginx 的配置文件。。。/etc/nginx/nginx.conf

(注意在最后补充两处会出现错误的地方,这里引用别人的经验,出现情况为./configure *: No such file or directory

网上寻求帮助找到的解决办法为   )

另外出现的问题的解决办法:根据提示,需要建立文件 (注意是文件,不是文件夹) /var/run/nginx.pid   .......


 12月14日

基本配置

1.Nginx的虚拟目录

1、创建目录

2、更改上下文

3、在配置文件/etc/nginx/nginx.conf 中添加alias

location /wt {

      alias "/web2";  

}

注意和apache中虚目录写法上的区别,上边添加的这个必须要在一个server内才会生效

2、Nginx的虚拟主机

1、基于ip的虚拟主机

ifconfig eth0:0 192.168.4.84添加一个ip

$ vim /etc/nginx/conf.d/default.conf

server {
    listen 192.168.1.84:80;   
    server_name  _;     
    location / {
        root   /web1;  
        index index.php  index.html index.htm;
    }
}
server {
    listen 192.168.1.85:80;   
    server_name  _;     
    location / {
        root   /web2;  
        index index.php  index.html index.htm;
    }
}

2、基于端口的虚拟主机

更改端口

yum -y install policycoreutils-python*

semanage port -l | grep http   # 查看SELinux下http相关端口

semanage port -a -t http_port_t -p tcp 82 #在selinux中添加82端口号

这一步很重要,很有用

$ vim /etc/nginx/conf.d/default.conf

server {
    listen 192.168.1.84:80;   
    server_name  _;     
    location / {
        root   /web1;  
        index index.php  index.html index.htm;
    }
}
server {
    listen 192.168.1.84:82;   
    server_name  _;     
    location / {
        root   /web2;  
        index index.php  index.html index.htm;
    }
}

3、基于域名

使用DNS或者hosts文件,本次实验用的hosts文件

$ vim /etc/hosts
192.168.1.83 www.baidu.com
192.168.1.83 www.taobao.com

$ vim /etc/nginx/conf.d/default.conf
server {
    listen 192.168.1.84:80;   
    server_name  www.baidu.com;     
    location / {
        root   /web1;  
        index index.php  index.html index.htm;
    }
}
server {
    listen 192.168.1.84:80;   
    server_name  www.taobao.com;     
    location / {
        root   /web2;  
        index index.php  index.html index.htm;
    }
}

12月15日

1、Nginx-basic身份认证

$ vim /etc/nginx/conf.d/default.conf

location /{
         root /web;
         index index.html index.htm;
         auth_basic "secret-web";
         auth_basic_user_file /etc/nginx/.passwd.db;
}

htpasswd -cm /etc/nginx/.passwd.db aaa

2、Nginx的tls站点加密传输

cd /etc/pki/tls/certs/

make junxi.pem #成成一个证书

$ vim /etc/nginx/conf.d/example_ssl.conf

server {
    listen 443 ssl;
    server_name localhost;
    ssl_certificate        /etc/pki/tls/certs/junxi.pem;
    ssl_certificate_key    /etc/pki/tls/certs/junxi.pem;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout 5m;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;
    location / {
        root /web1;
        index index.html index.htm;
    }
}