设为首页 收藏本站
查看: 740|回复: 0

[经验分享] Nginx应用实践入门

[复制链接]

尚未签到

发表于 2018-11-12 08:53:44 | 显示全部楼层 |阅读模式
  一、HTTP协议包含很多功能
  www是http功能之一
  www服务端口默认是80,OSI 第7层 应用层协议
  二、实现WWW服务的常用Web软件
  产品:nginx,apache(静态Web软件)
  三、经典的web组合
  LAMP(Linux apache mysql php)==》经典
  LNMP(Linux Nginx mysql php)==》国内非常流行
  四、Nginx介绍
  Nginx www服务软件,俄罗斯人开发,开源,性能很高
  Nginx本身是一款静态(html,js,css,jpg等)www软件,静态小文件(1M),高并发。
  同时占用的资源很少。3万并发进程,内存150M,不能解析PHP,JSP。
  Nginx 使用平台:unix,linux,windows即可使用。
  淘宝更改的nginx:tengine(http://tengine.taobao.org/)
[root@Qinglin-Test1 ~]# curl -I www.taobao.com  
HTTP/1.1 302 Found
  
Server: Tengine
  五、Nginx服务从大的方面的功能
  a. www web服务,邮件服务,邮件代理
  b. 负载均衡(反向代理proxy)
  c. webcache(web)缓存,相当于squid(CDN主要使用Squid)。
  六、Nginx特点
  1、配置简单,灵活,轻量。
  2、高并发(静态小文件),静态几万的并发
  3、占用资源少。2W并发,开10个线程服务,内存消耗几百M
  4、功能各类比较多(web,cache,proxy),每一个功能都不是特别强的功能
  5、支持epool模型。使得Nginix可以支持高并发。Apache选择的select模型。
  6、Nginx可以配合动态PHP服务(FastCGI接口)
  7、利用Nginx可以实现IP限制,可以限制连接数。
  它所具备 的其他WWW服务特性如下:
  支持基于名字、端口以及IP的多虚拟主机站点。
  可进行简单、方便、灵活的配置和管理。
  支持修改Nginx配置,并且在代码上线时,可以平滑重启,不中断业务访问。
  可自定义访问日志格式,临时缓冲写日志操作,快速日志轮训及通过syslog处理日志;
  可利用信息控制Nginix进程
  支持3xx-5xx http状态码重定向
  支持rewrite模块,支持URL重写及正规表达式匹配
  支持基于客户端IP地址和HTTP基本认证的访问控制
  支持PUT,DELETE,MKCOL,COPY以及MOVE等http请求
  方法:
  支持FLV流和MP4流技术产品应用;
  支持http响应速率限制
  支持同一IP地址的并发连接或请求数限制
  七、Nginx的应用场合
  1、提供静态服务器(图片、视频服务),另一个lighttpd。并发:几万并发
  2、提供动态服务,Nginx+Fastcgi的方式运行PHP,JSP。动态并发:500-1500
  3、提供反向代理,或称称为负载均衡。日PV2000万以下,并发1-2万都可以直接用Nginx做理。(相当于Haproxy,suid,F5,A10)
  4、提供缓存服务。类似Suid,varnish,ats。
  Nginx主机应用场景:
  1、Web服务器(首选)
  静态文件,nginx首选
  动态文件,配置fastcgi支持php
  2、反向代理(负载均衡),1000-2000W PV,并发6000
  3、缓存(使用的并不多)
  八、Nginx支持虚拟主机
  一个Server标签段就是一个虚拟主机
  1、基于域名的虚拟主机,通过域名来区分虚拟主机==》应用:外部网站
  2、基于端口的虚拟主机。通过端口来区分虚拟主机==》应用:公司内部网站,网站的后台。
  3、基于IP的虚拟主机。几乎不用。不支持ifconfig别名,配置文件可以。
  九、Nginx的安装
  Nginx官方地址:http://nginx.org/
  1、安装RCRE
  Pcre全称(Perl Compatible Regular Expressions)中文perl兼容正规表达示。
  官方地址:https://sourceforge.net/projects/pcre/files/pcre/
  下载的版本:pcre-8.30
  下载的地址:http://jaist.dl.sourceforge.net/project/pcre/pcre/8.30/pcre-8.30.tar.gz
  但是在生产环境中,我们一般使用yum安装。
  安装完成后,nginx会支持伪静态等perl的正规表达示。注:必装
  检查工作:检查自己的系统版本的内核版本,并检查是否此台服务器已经安装pcre了
  下面的结果已经显示出来pcre安装过了,但是没有安装pcre的开发包devel。
[root@Qinglin-Test1 ~]# cat /etc/redhat-release  
CentOS release 6.5 (Final)
  
[root@Qinglin-Test1 ~]# uname -r
  
2.6.32-431.23.3.el6.x86_64
  
[root@Qinglin-Test1 ~]# rpm -qa pcre pcre-devel
  
pcre-7.8-6.el6.x86_64
  yum安装pcre开发包
[root@Qinglin-Test1 ~]# yum -y install pcre pcre-devel  
Running Transaction
  
  Updating   : pcre-7.8-7.el6.x86_64                                        1/3
  
  Installing : pcre-devel-7.8-7.el6.x86_64                                  2/3
  
  Cleanup    : pcre-7.8-6.el6.x86_64                                        3/3
  
  Verifying  : pcre-7.8-7.el6.x86_64                                        1/3
  
  Verifying  : pcre-devel-7.8-7.el6.x86_64                                  2/3
  
  Verifying  : pcre-7.8-6.el6.x86_64                                        3/3
  

  
Installed:
  
  pcre-devel.x86_64 0:7.8-7.el6
  

  
Updated:
  
  pcre.x86_64 0:7.8-7.el6
  

  
Complete!
  再次检查安装的pcre包,检查已经发现devel包已经安装成功,结果如下:
[root@Qinglin-Test1 ~]# rpm -qa pcre pcre-devel  
pcre-7.8-7.el6.x86_64
  
pcre-devel-7.8-7.el6.x86_64
  2、安装opnssl开发包
  该服务是支持SSL 443的服务,也是必须安装的
[root@Qinglin-Test1 ~]# yum install -y openssl-devel  
Installed:
  
  openssl-devel.x86_64 0:1.0.1e-48.el6_8.1
  

  
Dependency Installed:
  
  keyutils-libs-devel.x86_64 0:1.4-5.el6
  
  krb5-devel.x86_64 0:1.10.3-57.el6
  
  libcom_err-devel.x86_64 0:1.41.12-22.el6
  
  libselinux-devel.x86_64 0:2.0.94-7.el6
  
  libsepol-devel.x86_64 0:2.0.41-4.el6
  
  zlib-devel.x86_64 0:1.2.3-29.el6
  

  
Dependency Updated:
  
  e2fsprogs.x86_64 0:1.41.12-22.el6      e2fsprogs-libs.x86_64 0:1.41.12-22.el6
  
  keyutils-libs.x86_64 0:1.4-5.el6       krb5-libs.x86_64 0:1.10.3-57.el6
  
  libcom_err.x86_64 0:1.41.12-22.el6     libselinux.x86_64 0:2.0.94-7.el6
  
  libselinux-utils.x86_64 0:2.0.94-7.el6 libss.x86_64 0:1.41.12-22.el6
  
  openssl.x86_64 0:1.0.1e-48.el6_8.1
  

  
Complete!
  查安装的openssl包,检查已经发现devel包已经安装成功,结果如下:
[root@Qinglin-Test1 ~]# rpm -qa openssl*  
openssl-devel-1.0.1e-48.el6_8.1.x86_64
  
openssl-1.0.1e-48.el6_8.1.x86_64
  3、安装Nginx服务
  检查是否本台服务器安装了nginx,发现并没有安装,如下:
[root@Qinglin-Test1 ~]# rpm -qa nginx  
[root@Qinglin-Test1 ~]#
  本次版本使用1.6.3,stable是稳定版,也可以使用1.8.0
  开始准备安装
  下载地址:http://nginx.org/download/nginx-1.6.3.tar.gz
  在本地创建一个专于用下载的目录,并进行下载。
[root@Qinglin-Test1 /]# mkdir /home/tools/ -p  
[root@Qinglin-Test1 /]# cd /home/tools/
  
[root@Qinglin-Test1 tools]# wget http://nginx.org/download/nginx-1.6.3.tar.gz
  
--2016-06-25 21:34:07--  http://nginx.org/download/nginx-1.6.3.tar.gz
  
Resolving nginx.org... 95.211.80.227, 206.251.255.63, 2001:1af8:4060:a004:21::e3
  
Connecting to nginx.org|95.211.80.227|:80... connected.
  
HTTP request sent, awaiting response... 200 OK
  
Length: 805253 (786K) [application/octet-stream]
  
Saving to: “nginx-1.6.3.tar.gz”
  

  
100%[======================================>] 805,253      515K/s   in 1.5s
  

  
2016-06-25 21:34:10 (515 KB/s) - “nginx-1.6.3.tar.gz” saved [805253/805253]
  

  
[root@Qinglin-Test1 tools]# ls
  
nginx-1.6.3.tar.gz
  创建nginx专用用户并检查
  -s /sbin/nologin是不允许登陆,-M是不创建家目录
[root@Qinglin-Test1 nginx-1.6.3]# useradd nginx -s /sbin/nologin -M  
[root@Qinglin-Test1 nginx-1.6.3]# cat /etc/passwd|grep nginx
  
nginx:x:500:500::/home/nginx:/sbin/nologin
  思路:解压、编译安装,并使用echo $?查看返回值是否为0,非0都是错误的。
[root@Qinglin-Test1 tools]# tar -xf nginx-1.6.3.tar.gz  
[root@Qinglin-Test1 tools]# cd nginx-1.6.3
  
[root@Qinglin-Test1 nginx-1.6.3]# ls
  
auto     CHANGES.ru  configure  html     man     src
  
CHANGES  conf        contrib    LICENSE  README
  
[root@Qinglin-Test1 nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
  

  
Configuration summary
  
  + using system PCRE library
  
  + using system OpenSSL library
  
  + md5: using OpenSSL library
  
  + sha1: using OpenSSL library
  
  + using system zlib library
  

  
  nginx path prefix: "/app/application/nginx-1.6.3"
  
  nginx binary file: "/app/application/nginx-1.6.3/sbin/nginx"
  
  nginx configuration prefix: "/app/application/nginx-1.6.3/conf"
  
  nginx configuration file: "/app/application/nginx-1.6.3/conf/nginx.conf"
  
  nginx pid file: "/app/application/nginx-1.6.3/logs/nginx.pid"
  
  nginx error log file: "/app/application/nginx-1.6.3/logs/error.log"
  
  nginx http access log file: "/app/application/nginx-1.6.3/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"
  

  
[root@Qinglin-Test1 nginx-1.6.3]# echo $?
  
0
  
make[1]: Leaving directory `/home/tools/nginx-1.6.3'
  
[root@Qinglin-Test1 nginx-1.6.3]# echo $?
  
0
  
[root@Qinglin-Test1 nginx-1.6.3]# make install
  
make[1]: Leaving directory `/home/tools/nginx-1.6.3'
  注:./config是可以--help的,查看你安装的模块
[root@Qinglin-Test1 nginx-1.6.3]# ./configure --help  

  
  --help                             print this message
  

  
  --prefix=PATH                      set installation prefix
  
  --sbin-path=PATH                   set nginx binary pathname
  
  --conf-path=PATH                   set nginx.conf pathname
  
  --error-log-path=PATH              set error log pathname
  
  --pid-path=PATH                    set nginx.pid pathname
  
  --lock-path=PATH                   set nginx.lock pathname
  

  
  --user=USER                        set non-privileged user for
  
                                     worker processes
  
  --group=GROUP                      set non-privileged group for
  
                                     worker processes
  
  --with-http_ssl_module             enable ngx_http_ssl_module
  
  --with-http_stub_status_module     enable ngx_http_stub_status_module
  解释:
  ./configure 是生成makefile文件,实际是个配置过程
  make 就是编译生成的配置makefile文件
  make install 是真正安装的过程
  参数说明:
  --prefix= 指定安装的目录
  --user= 指定nginx的用户是什么,不指定默认nobody
  --group= 指定nginx的组是什么,不指定默认nobody
  --with-http_ssl_module 指定nginx使用ssl模块,支持443端口的https
  --with-http_stub_status_module  状态模块,比如检查连接数等等,可以用来监控。
  安装的最后于一步,创建软连接,ln一定要写全路径
[root@Qinglin-Test1 nginx-1.6.3]# cd /application/  
[root@Qinglin-Test1 application]# ls
  
nginx-1.6.3
  
[root@Qinglin-Test1 application]# ln -s /application/nginx-1.6.3/ /application/nginx
  
[root@Qinglin-Test1 application]# ll
  
total 4
  
lrwxrwxrwx 1 root root   25 Jun 25 21:59 nginx -> /application/nginx-1.6.3/
  
drwxr-xr-x 6 root root 4096 Jun 25 21:59 nginx-1.6.3
  4、启动Nginx,并检查
  执行完不报错,一般情况下说明启动成功了
  进程中有一个master可以理解成领导,实际上功作的是woker
[root@Qinglin-Test1 application]# /application/nginx/sbin/nginx  
[root@Qinglin-Test1 application]# ps -ef|grep nginx|grep -v grep
  
root      4597     1  0 22:08 ?        00:00:00 nginx: master process /application/nginx/sbin/nginx
  
nginx     4598  4597  0 22:08 ?        00:00:00 nginx: worker process
  检查端口,如下,80已经启动了
[root@Qinglin-Test1 application]# netstat -lntup  
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:80                  0.0.0.0:*                   LISTEN      4597/nginx
  本地使用curl命令检测是否启动成功
[root@Qinglin-Test1 application]# curl 127.0.0.1  

  

  

  
Welcome to nginx!
  通过浏览器访问,如果不通,检查一下iptables
DSC0000.png

  5、查看nginx的编译过的参数
  如果到一家新公司,想查看安装时是如何编译的,使用-V,方法如下:
[root@Qinglin-Test1 /]# /application/nginx/sbin/nginx -V  
nginx version: nginx/1.6.3
  
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
  
TLS SNI support enabled
  
configure arguments: --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
  6、排错
  错误1:可能是iptables规则不允许
  错误2:selinux
  排错日志:/var/log/messages
  /nginx/log/error.log
  十、部署一个WEB页面
  1、了解Nginx重要目录
  排除掉nginx目录下的tmp目录
  conf配置文件目录
  html默认网站目录
  sbin启动命令
  logs错误,访问,pid目录
[root@Qinglin-Test1 nginx]# cd /application/nginx/  
[root@Qinglin-Test1 nginx]# cd /
  
[root@Qinglin-Test1 /]# cd /application/nginx/
  
[root@Qinglin-Test1 nginx]# ls -v |grep -v temp
  
conf
  
html
  
logs
  
sbin
  2、部署一个默认站点(html目录)
  进入到html目录,将原来的index.html改名,并重新写一个index.html
[root@Qinglin-Test1 nginx]# cd html/  
[root@Qinglin-Test1 html]# ls
  
50x.html  index.html
  
[root@Qinglin-Test1 html]# mv index.html index.html.bak
  
[root@Qinglin-Test1 html]# ls
  
50x.html  index.html.bak
  
[root@Qinglin-Test1 html]# vim index.html
  

  
Qinglin.s Nginx Server Test Page
  

  
Hi,This My Test Page!
  
My Blog address is Qinglin Blog
  

  

  改html的内容不需要重启nginx,现在测试一下页面是否可以访问
DSC0001.png

  十一、Nginx模块汇总
  模块文档:http://nginx.org/en/docs/
  http://tengine.taobao.org/documentation_cn.html
  常用模块汇总表:
DSC0002.png

  十二、Nginx目录结构
[root@Qinglin-Test1 application]# tree nginx  
nginx
  
├── client_body_temp            ==> 客户端内容的临时文件
  
├── conf                        ==> 这是Nginx的所有配置文件的目录
  
│   ├── fastcgi.conf
  
│   ├── fastcgi.conf.default
  
│   ├── fastcgi_params          ==> 配置PHP的动态配置文件
  
│   ├── fastcgi_params.default  ==> 以.default都是nginx自动帮助备份的配置文件
  
│   ├── koi-utf
  
│   ├── koi-win
  
│   ├── mime.types
  
│   ├── mime.types.default
  
│   ├── nginx.conf              ==> 核心文件,主要配置nginx静态
  
│   ├── nginx.conf.default      ==> 以.default都是nginx自动帮助备份的配置文件
  
│   ├── scgi_params
  
│   ├── scgi_params.default
  
│   ├── uwsgi_params
  
│   ├── uwsgi_params.default
  
│   └── win-utf
  
├── fastcgi_temp
  
├── html                        ==> 默认的站点目录
  
│   ├── 50x.html                ==> 错误页面替代显示文件,例如502就会调用该页面
  
│   ├── index.html              ==> 首页文件在nginx定义好的默认html欢迎页
  
│   └── index.html.bak
  
├── logs                        ==> Nginx日志目录的默认路径,包括错误日志及访问日志
  
│   ├── access.log              ==> 访问日志
  
│   ├── error.log               ==> 错误日志,nginx故障问题会呈现到这里
  
│   └── nginx.pid               ==> Nginx的pid文件,Nginx进程启动后,会把PID号写到这里
  
├── proxy_temp                  ==> 代表的临时文件
  
├── sbin                        ==> 这是Nginx命令的目录,如Nginx的启动命令
  
│   └── nginx                   ==> Nginx的启动文件命令
  
├── scgi_temp                   ==> 临时文件
  
└── uwsgi_temp                  ==> 临时文件
  

  
9 directories, 22 files
  十三、Nginx主配置文件框架(nginx.conf)
[root@Qinglin-Test1 conf]# cat nginx.conf  

  
user  nobody;             ==> 指定nginx使用的用户
  
worker_processes  1;      ==> 指定几个worker进程有几个,填写时参考CPU核数
  

  
error_log  logs/error.log;           ==> 错误日志路径
  
error_log  logs/error.log  notice;   ==> 日志级别警告
  
error_log  logs/error.log  info;     ==> 日志信息
  

  
pid        logs/nginx.pid;           ==> pid(进程标识符)
  

  

  
events {                             ==> 事件区块开始
  
    worker_connections  1024;        ==> 每个work进程支持最大连接数,在这里设置,可以理解成并发,算并法是worker数*1024
  
}
  

  

  
http {                                ==> HTTP区块开始
  
    include       mime.types;         ==> 指定mime类型,类型mime.type定义
  
    default_type  application/octet-stream;   ==> 默认的媒体类型
  

  
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  
                      '$status $body_bytes_sent "$http_referer" '
  
                      '"$http_user_agent" "$http_x_forwarded_for"';
  

  
    access_log  logs/access.log  main;  ==> 访问日志
  

  
    sendfile        on;                 ==> 开启高效文件传输模式
  
    tcp_nopush     on;                  ==> 防止网络阻塞
  
    keepalive_timeout  65;              ==> 长连接超时时间,单位是秒
  

  
    gzip  on;                           ==> 开启gzip压缩输出
  

  
    server {                            ==> 一个server标签就是一个虚拟机
  
        listen       80;                ==> 服务的端口
  
        server_name  localhost;         ==> 配置域名
  

  
        access_log  logs/host.access.log  main;
  

  
        location / {                    ==> 以/后开始的匹配的URI,比如/123/index.html
  
             root   html;               ==> 存放html的路径,默认在配置文件中的html里
  
            index  index.html index.htm;  ==> 默认的首页文件,多个空格分开
  
        }
  
  注:如果location页面为/50x.html就优化在=号的location里找。
  十四、基于域名配置虚拟主机
  将配置文件最少化,grep排除掉备份使用的nginx.conf.default重定向到nginx.cnf,这样就没有注释的内容。
[root@Qinglin-Test1 conf]# grep -Ev "#|^$" nginx.conf.default >nginx.conf  
[root@Qinglin-Test1 conf]# cat 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  localhost;
  
        location / {
  
            root   html;
  
            index  index.html index.htm;
  
        }
  
        error_page   500 502 503 504  /50x.html;
  
        location = /50x.html {
  
            root   html;
  
        }
  
    }
  
}
  创建两个不同域名虚拟主机,一个是qinglin.com和guanqinglin.com
  下列标红的为修改的重点内容,一个是指定域名,一个是指定html目录
[root@Qinglin-Test1 conf]# vim nginx.conf  
    worker_connections  1024;
  
}
  
http {
  
    include       mime.types;
  
    default_type  application/octet-stream;
  
    sendfile        on;
  
    keepalive_timeout  65;
  
    server {
  
        listen       80;
  
        server_name  www.qinglin.com;
  
        location / {
  
            root   html/qinglin;
  
            index  index.html index.htm;
  
        }
  
        }
  
    server {
  
        listen       80;
  
        server_name  www.guanqinglin.com;
  
        location / {
  
            root   html/guanqinglin;
  
            index  index.html index.htm;
  
        }
  
        }
  创建root定义的qinglin和guanqinglin的目录,并创建index.html文件
[root@Qinglin-Test1 conf]# mkdir /application/nginx/html/{qinglin,guanqinglin} -p  
[root@Qinglin-Test1 conf]# echo "qinglin" >/application/nginx/html/qinglin/index.html
  
[root@Qinglin-Test1 conf]# echo "guanqinglin" >/application/nginx/html/guanqinglin/index.html
  
[root@Qinglin-Test1 conf]# cat /application/nginx/html/qinglin/index.html
  
qinglin
  
[root@Qinglin-Test1 conf]# cat /application/nginx/html/guanqinglin/index.html
  
guanqinglin
  检查语法并平滑重启服务
[root@Qinglin-Test1 conf]# /application/nginx/sbin/nginx -t  
nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
  
nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
  
[root@Qinglin-Test1 conf]# /application/nginx/sbin/nginx -s reload
  
[root@Qinglin-Test1 conf]#
  修改客户机hosts来校验结果
DSC0003.png

DSC0004.png

  注:虽然指定了不同域名不同主机,但是使用IP访问,他会给第一个虚拟主机的配置
  配置虚拟主机流程
  1)复制一个完整的server标签段,到结尾,注意:要放到http的结束大括号前,也就是server标签段放入httpd段落中。
  2)更改server_name及对应网页的root根目录。
  3)检查配置文件语法,平滑重启。
  4)创建server_name 对应网页的根目录,并且建立测试文件,如果没有index首页会出现404错误。
  5)在客户端对server_name的主机名对host解析或DNS配置,并检查(ping 域名看返回的IP对不对)。
  6)win32 浏览器访问,或者在linux客户端做host解析,用wget或curl访问。
  十四、基于端口配置虚拟主机
  配置虚拟主机监听的端口
[root@Qinglin-Test1 conf]# vim nginx.conf  
    worker_connections  1024;
  
}
  
http {
  
    include       mime.types;
  
    default_type  application/octet-stream;
  
    sendfile        on;
  
    keepalive_timeout  65;
  
    server {
  
        listen       8081;
  
        server_name  www.qinglin.com;
  
        location / {
  
            root   html/qinglin;
  
            index  index.html index.htm;
  
        }
  
        }
  
    server {
  
        listen       8082;
  
        server_name  www.guanqinglin.com;
  
        location / {
  
            root   html/guanqinglin;
  
            index  index.html index.htm;
  
        }
  
        }
  
"nginx.conf" 26L, 594C written
  检查语法并重新启动
[root@Qinglin-Test1 conf]# /application/nginx/sbin/nginx -t  
nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
  
nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
  
[root@Qinglin-Test1 conf]# /application/nginx/sbin/nginx -s reload
  
[root@Qinglin-Test1 conf]#
  检查端口并测试
[root@Qinglin-Test1 conf]# netstat -lntup|grep 808*  
tcp        0      0 0.0.0.0:8081                0.0.0.0:*                   LISTEN      4597/nginx
  
tcp        0      0 0.0.0.0:8082                0.0.0.0:*                   LISTEN      4597/nginx
DSC0005.png

DSC0006.png

  十五、基于IP配置虚拟主机
[root@Qinglin-Test1 conf]# vim nginx.conf  
    worker_connections  1024;
  
}
  
http {
  
    include       mime.types;
  
    default_type  application/octet-stream;
  
    sendfile        on;
  
    keepalive_timeout  65;
  
    server {
  
        listen       192.168.1.1:80;
  
        server_name  www.qinglin.com;
  
        location / {
  
            root   html/qinglin;
  
            index  index.html index.htm;
  
        }
  
        }
  
    server {
  
        listen       192.168.1.1:80;
  
        server_name  www.guanqinglin.com;
  
        location / {
  
            root   html/guanqinglin;
  
            index  index.html index.htm;
  
        }
  
        }
  
"nginx.conf" 26L, 594C written



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-633923-1-1.html 上篇帖子: nginx学习总结二(nginx的启动停止以及版本平滑升级) 下篇帖子: 编写nginx服务配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表