Linux下nginx的使用




day02 
1.远程连接服务器故障排查
1)道路是否通畅
2)是否有劫财劫色
xxxxxx no route to host  xxxx 
3)洗浴中心是否提供你想要的服务
sshd远程连接服务 == 22 

ip 端口 用户名 密码 

ll /var/log/secure #用户访问系统的记录

rz  windows文件上传到linux
sz  把Linux文件下载到windows

.tar.gz 


.zip压缩包是linux和windows默认支持的。


unzip secure-20161219.zip 

xshell   远程连接 
xftp     ftp工具 
https://www.netsarang.com/download/down_form.html?code=523

查看日志 
1.less   f或空格向下一页  b上一页
2.head/tail 
3.grep 

grep 'Failed password'  secure-20161219


2.命令 













2.


day03
1.yum源  使用光盘里面的rpm包
2.关闭 iptables 和selinux 
1)当前正在运行的
/etc/init.d/iptables stop 

2)关门开机自启动
chkconfig iptables off 
3.运行级别与单用户 
4.定时任务

linux启动过程


http请求与响应过程




nginx 
wget http://nginx.org/download/nginx-1.12.2.tar.gz


编译安装nginx前的准备
1.添加一个用户
useradd -s /sbin/nologin -M  www 
#创建虚拟用户 
#linux每个进程要有一个对应的用户

[root@oldboyedu-s6 nginx-1.12.2]# id www
uid=501(www) gid=501(www) groups=501(www)
[root@oldboyedu-s6 nginx-1.12.2]# su - www
su: warning: cannot change directory to /home/www: No such file or directory
This account is currently not available.

2.安装nginx依赖软件包
#pcre-devel       perl语言的兼容正则表达式
#openssl-devel    https


yum install pcre-devel openssl-devel -y

[root@oldboyedu-s6 nginx-1.12.2]# rpm -qa pcre-devel openssl-devel 
pcre-devel-7.8-7.el6.x86_64
openssl-devel-1.0.1e-57.el6.x86_64

##
##[root@oldboyedu-s6 ~]# ll  /mnt/Packages/pcre-devel-7.8-7.el6.x86_64.rpm  /mnt/Packages/openssl-devel-1.0.1e-57.el6.x86_64.rpm 
##-r--r--r-- 2 root root 1227684 Mar 23  2017 /mnt/Packages/openssl-devel-1.0.1e-57.el6.x86_64.rpm
##-r--r--r-- 2 root root  327960 Jul 25  2015 /mnt/Packages/pcre-devel-7.8-7.el6.x86_64.rpm
##

3.编译安装nginx 

./configure  --user=www --group=www --prefix=/application/nginx-1.12.2 --with-http_stub_status_module  --with-http_ssl_module
#--user   用户 
#--group  用户组
#--prefix 安装到哪里
#两个模块--with-http_stub_status_module  --with-http_ssl_module

echo $?

make 

make install 



[root@oldboyedu-s6 ~]# md5sum /root/nginx-1.12.2.tar.gz 
4d2fc76211435f029271f1cf6d7eeae3  /root/nginx-1.12.2.tar.gz




[root@oldboyedu-s6 nginx-1.12.2]# /application/nginx-1.12.2/sbin/nginx -t
nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful


[root@oldboyedu-s6 nginx-1.12.2]# /application/nginx-1.12.2/sbin/nginx 
[root@oldboyedu-s6 nginx-1.12.2]# ss -lntup|grep 80
tcp    LISTEN     0      128                    *:80                    *:*      users:(("nginx",4377,6),("nginx",4378,6))



[root@oldboyedu-s6 nginx-1.12.2]# pwd
/application/nginx-1.12.2
[root@oldboyedu-s6 nginx-1.12.2]# ll
total 36
drwx------ 2 www  root 4096 Mar 15 10:31 client_body_temp
drwxr-xr-x 2 root root 4096 Mar 15 10:00 conf             nginx配置文件的目录
drwx------ 2 www  root 4096 Mar 15 10:31 fastcgi_temp
drwxr-xr-x 2 root root 4096 Mar 15 10:00 html             nginx站点目录 网站的根目录 
drwxr-xr-x 2 root root 4096 Mar 15 10:31 logs             nginx日志
drwx------ 2 www  root 4096 Mar 15 10:31 proxy_temp
drwxr-xr-x 2 root root 4096 Mar 15 10:00 sbin             nginx命令
drwx------ 2 www  root 4096 Mar 15 10:31 scgi_temp
drwx------ 2 www  root 4096 Mar 15 10:31 uwsgi_temp


├── client_body_temp
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf                  #nginx的主配置文件 
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp
├── html
│   ├── 50x.html
│   └── index.html                  #网站默认的首页文件 
├── logs
│   ├── access.log                  #访问日志
│   ├── error.log
│   └── nginx.pid
├── proxy_temp
├── sbin
│   └── nginx
├── scgi_temp
└── uwsgi_temp

9 directories, 21 files


10.0.0.1 - - [15/Mar/2018:10:44:47 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "http://10.0.0.200/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"
10.0.0.1 - - [15/Mar/2018:10:44:50 +0800] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"
10.0.0.1 - - [15/Mar/2018:10:44:50 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "http://10.0.0.200/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"
10.0.0.1 - - [15/Mar/2018:10:44:51 +0800] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"
10.0.0.1 - - [15/Mar/2018:10:44:51 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "http://10.0.0.200/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"
10.0.0.1 - - [15/Mar/2018:10:44:51 +0800] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"
10.0.0.1 - - [15/Mar/2018:10:44:51 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "http://10.0.0.200/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"



egrep -v '^$|#'  conf/nginx.conf.default >conf/nginx.conf


#优雅的重启nginx √√√√√√
/application/nginx-1.12.2/sbin/nginx  -s reload 

#关闭nginx 然后开启
/application/nginx-1.12.2/sbin/nginx  -s stop 
/application/nginx-1.12.2/sbin/nginx  



mkdir -p /application/nginx-1.12.2/html/{www,bbs,blog}

for name in www bbs blog;do echo $name.etiantian.org> /application/nginx-1.12.2/html/$name/index.html ;done
for name in www bbs blog;do cat /application/nginx-1.12.2/html/$name/index.html ;done

[root@oldboyedu-s6 nginx-1.12.2]# cat conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.etiantian.org;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}


[root@oldboyedu-s6 nginx-1.12.2]# /application/nginx-1.12.2/sbin/nginx -t
nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful
[root@oldboyedu-s6 nginx-1.12.2]# /application/nginx-1.12.2/sbin/nginx -s reload 


搭建www.etiantian.org网站流程
1.修改nginx.conf文件 

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.etiantian.org;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

2.创建环境 
mkdir -p /application/nginx-1.12.2/html/{www,bbs,blog}
for name in www bbs blog;do echo $name.etiantian.org> /application/nginx-1.12.2/html/$name/index.html ;done
for name in www bbs blog;do cat /application/nginx-1.12.2/html/$name/index.html ;done

3.检查语法并重启 

[root@oldboyedu-s6 nginx-1.12.2]# /application/nginx-1.12.2/sbin/nginx -t
nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful
[root@oldboyedu-s6 nginx-1.12.2]# /application/nginx-1.12.2/sbin/nginx -s reload 

4.windows测试 浏览器(注意缓存)
1)修改 etchosts 
10.0.0.200  www.etiantian.org bbs.etiantian.org blog.etiantian.org 

2)浏览器测试 

5.Linux命令行测试 
curl -vH Host: www.etiantian.org 10.0.0.200


排错流程:
1.linux命令行是否能显示 
curl -vH Host:www.etiantian.org 10.0.0.200

2.windows 本地shell 
ping 



[root@oldboyedu-s6 nginx-1.12.2]# cat conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.etiantian.org;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {      
        listen       80;
        server_name  bbs.etiantian.org;
        location / {
            root   html/bbs;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }   
    server {      
        listen       80;
        server_name  blog.etiantian.org;
        location / {
            root   html/blog;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }   

}


[root@oldboyedu-s6 nginx-1.12.2]# curl -H Host:bbs.etiantian.org 10.0.0.200
bbs.etiantian.org
[root@oldboyedu-s6 nginx-1.12.2]# curl -H Host:blog.etiantian.org 10.0.0.200
blog.etiantian.org





小结:
1.软件目录 配置文件讲解 
2.搭建www网站
3.搭建多个网站(虚拟主机)


location 

“~”用于区分大小写(大小写敏感)的匹配;   ~ /images {}

“~*” 用于不区分大小写的匹配。还可以用逻辑操作符!对上面的匹配取反,即!~ 和 !~*。


“^~”作用是在常规的字符串匹配检查之后,不做正则表达式的检查,即如果最明确的那个字符串匹配的location配置中有此前缀,那么不做正则表达式的检查。



 

[root@oldboyedu-s6 nginx-1.12.2]# cat  conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

server {
    listen       80;
    server_name  www.etiantian.org etiantian.org;
    root   html/www;
    location / {
       return 401;
    }

    location /documents/ {
        return 403;
    }
    location ^~ /images/ {
        return 404;
    }
    location ~* .(gif|jpg|jpeg)$ {
        return 500;
    }
  }
}



^~
~*
/documents/
/


第1名:“location  ~* .(gif|jpg|jpeg)$ {”     正则匹配
第2名:“location  /documents/ {”     匹配常规字符串,如果有正则则优先匹配正则。
第3名:“location  / {”     所有location都不能匹配后的默认匹配。



[root@oldboyedu-s6 nginx-1.12.2]# curl -I  10.0.0.200
HTTP/1.1 401 Unauthorized
Server: nginx/1.12.2
Date: Thu, 15 Mar 2018 04:13:41 GMT
Content-Type: text/html
Content-Length: 195
Connection: keep-alive

[root@oldboyedu-s6 nginx-1.12.2]# 
[root@oldboyedu-s6 nginx-1.12.2]# curl -I  10.0.0.200/documents/index.html
HTTP/1.1 403 Forbidden
Server: nginx/1.12.2
Date: Thu, 15 Mar 2018 04:14:42 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

[root@oldboyedu-s6 nginx-1.12.2]# curl -I  10.0.0.200/documents/w.jpg
HTTP/1.1 500 Internal Server Error
Server: nginx/1.12.2
Date: Thu, 15 Mar 2018 04:15:56 GMT
Content-Type: text/html
Content-Length: 193
Connection: close

[root@oldboyedu-s6 nginx-1.12.2]# 
[root@oldboyedu-s6 nginx-1.12.2]# curl -I  10.0.0.200/images/www.jpg
HTTP/1.1 404 Not Found
Server: nginx/1.12.2
Date: Thu, 15 Mar 2018 04:16:52 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive







小结:
0.linux启动过程
1.nginx 软件目录 配置文件讲解 
2.搭建www网站
3.搭建多个网站(虚拟主机)
4.nginx location 用法 


redis 










day03
1.yum源  使用光盘里面的rpm包
2.关闭 iptables 和selinux 
1)当前正在运行的
/etc/init.d/iptables stop 

2)关门开机自启动
chkconfig iptables off 
3.运行级别与单用户 
4.定时任务

linux启动过程

day02 
1.远程连接服务器故障排查
ll /var/log/secure #用户访问系统的记录
2.lrzsz zip tar 
rz  windows文件上传到linux
sz  把Linux文件下载到windows
unzip secure-20161219.zip 
查看日志 
1).less   f或空格向下一页  b上一页
2).head/tail 
3).grep 

grep 'Failed password'  secure-20161219

2.命令 


day01 
1.
原文地址:https://www.cnblogs.com/ldq1996/p/8583490.html