01-Nginx的安装分享

Author:

https://github.com/zhaojunlike

Mark:

总结生活的点滴和他人分享,知识是没有高低的,多年后回头来看,才能找出思想的遗漏。欢迎各路老司机带路,重喷,我也虚心接受

Why:

热爱技术的群体。

对Web服务器的理解

搭建Web服务器尝鲜

流行的Web服务器

Apache与Nginx的优缺点

如今我已经将所有的服务器的lamp环境,全部替换成lnmp环境

优缺点:

Nginx优点:
- Nginx相当于Apache的使用,更加的方便和简单。
- 和Nodejs很多原理一样,Nginx也同样是异步非阻塞的,所以Nginx可以保证高并发。
- 并且如今感觉Nginx的社区也非常的强大,用户量也占有了很大一部分,一个产品的好不好也可以从社区体现的。
- 各种配置简单,明了,类Json的格式配置,更加的人性化,相对于Apache的配置来说,更加的方便
- 我个人不赞同Apache的Rewrite比Nginx强大
- 模块开发简单,高性能和高可用
- 反向代理配置简单,集群方便

Apache优点:
- 稳定我之前看到很多老的企业,他们的web服务器大多都是IIS和Apache,也足以说明Apache的稳定性。
-

以上是我个人的胡话,我不够太深入,只是在使用过程中对2个web服务器的比较,在我学PHP的时候,那个时候都是lamp环境,自从我去学习了nginx,就再也不想去关心apache那繁琐复杂的配置,nginx一个官方文档就搞定。[Nginx-Docs](http://nginx.org/en/docs/)

Start Test:

Linux环境,安装Nginx

  • 这里我们需要有linux的基础,我个人很推荐尽快去学习linux,你会体会到命令模式的独特魅力
  • 所选环境 centos7.2
  • 下载最新版本的stable的源代码包
    我选择了1.10 download

    #mkdir /home/download/nginx
    #cd /home/download/nginx
    #wget http://nginx.org/download/nginx-1.10.2.tar.gz
    说明1.:我个人有洁癖,所以每一个文件我都喜欢好好的存放和管理起来,所以我创建了一个download/nginx用于放我的文件,也推荐每个人去整理自己的资料。
    说明2.:如果遇到了wget找不到,请yum install wget一下
    #tar -zxf ./nginx.....
    #cd nginx-1.10.2
    说明:好了下载nginx已经拉下来了,下一步我们去到官方文档,去看看文档当中的安装教程
    文档在这儿: http://nginx.org/en/docs/configure.html
    #./configure --help           
    说明:查看一下配置所需要的一些参数,参数说明请去看文档喔,这里我们就直接安装了
    #./configure --prefix=/usr/local/nginx1.10
    #make && make install
    如下错误:
     msg:./configure: error: C compiler cc is not found
    
  • #yum install gcc
    try again
    如下错误:
     msg:
     ./configure: error: the HTTP rewrite module requires the PCRE library.
    
    You can either disable the module by using --without-http_rewrite_module
    option, or install the PCRE library into the system, or build the PCRE library
    statically from the source with nginx by using --with-pcre=<path> option.
>```


>>Chinese:http重写模块需要pcre lib库,你可以配置--with-out..去取消这个模块,否则请安装pcre到system库,或者指定您安装的--with-pcre=path >#好,既然他需要这个东西,我们就去安装就行了 >上图: >

>```
>这下尴尬了,系统说已经装了这个东西了。不急,我们先看看dev开发版本得库是不是安装了
>,因为软件编译嘛,肯定是需要开发版本的源代码,才可以编译,至少我个人是这么理解的。那我去试一试
>```
>```
>哎哟,有这个,管他的装上再说
>然后再试一试编译
>。。。。过度时间,么么哒
>```
>```
>哎呀又是一个gzip库,我们按照原来的方式去处理就行了
>#yum install zlib
>#yum install zlib-devel
>然后接着再尝试
>....等待时间,么么哒
>哎哟,成功了哟
>```

总结

  • nginx安装需要的一些工具:gcc
  • nginx需要的一些基本库:zlib-devel,pcre-devel,

完成安装

#make && make install

信号量的概念

what is signal? let's see

我们之前再windows基本上都没有听过信号量这个概念,这学期有一门操作系统的课程,就讲到信号量这个盖联:

  • 信号量的使用主要是用来保护共享资源,使得资源在一个时刻只有一个进程(线程)所拥有。(啧啧,听不懂)
  • 。。。。。
  • 不管了,想去看的请自行百度
  • 来接下来我们看文档
doc:
        Starting, Stopping, and Reloading Configuration
        
        To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:
        
        ##nginx -s signal
        Where signal may be one of the following:
        
        stop — fast shutdown
        quit — graceful shutdown
        reload — reloading the configuration file
        reopen — reopening the log files
        For example, to stop nginx processes with waiting for the worker processes to finish serving current requests, the following command can be executed:
        
        #nginx -s quit
        This command should be executed under the same user that started nginx.
        Changes made in the configuration file will not be applied until the command to reload configuration is sent to nginx or it is restarted. To reload configuration, execute:
        
        #nginx -s reload
        Once the master process receives the signal to reload configuration, it checks the syntax validity of the new configuration file and tries to apply the configuration provided in it. If this is a success, the master process starts new worker processes and sends messages to old worker processes, requesting them to shut down. Otherwise, the master process rolls back the changes and continues to work with the old configuration. Old worker processes, receiving a command to shut down, stop accepting new connections and continue to service current requests until all such requests are serviced. After that, the old worker processes exit.
        
        A signal may also be sent to nginx processes with the help of Unix tools such as the kill utility. In this case a signal is sent directly to a process with a given process ID. The process ID of the nginx master process is written, by default, to the nginx.pid in the directory /usr/local/nginx/logs or /var/run. For example, if the master process ID is 1628, to send the QUIT signal resulting in nginx’s graceful shutdown, execute:
        
        #kill -s QUIT 1628
        For getting the list of all running nginx processes, the ps utility may be used, for example, in the following way:
        
        #ps -ax | grep nginx
        For more information on sending signals to nginx, see Controlling nginx.

我只看到了几个重要的,来来来看下:

  • nginx -s $param 发送信号

  • nginx -s stop 停止

  • nginx -s reload 重启
    走着先不管,我们去试一试

  • 因为我是

  • 走:请求一下 http://ip/

  • 发现访问不了,尴尬,我的是跑的虚拟机,没道理啊,我xshell都能连,就说明我ip是正确的,所以我确定可能是端口没有开放访问

开放80web端口

  • 1.找到我们的防火墙兄弟:# vim /etc/sysconfig/iptables
  • 2.记住,不懂得东西,千万不要放过任何一个提示,任何一行英文,否则你懂得。。。。、
  • 3.现在看看22端口
  • 4.#按照他得方式给他一个:-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
  • 5.想知道这些参数的什么意思,请自行百度哈
  • 6.改了配置总得重启吧? 走着: # systemctl restart iptables
  • 7.对了,新版的linux 好像都在使用systemctl来进行service控制了,我们要跟上时代的脚步喔
  • 成功了

和nginx交流

nginx的配置

运维所需要的知识

nginx配搭PHP

nginx进行rewrite重写和重写规则

压力测试

nginx的反向代理

nginx的集群

推荐网址

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 222,000评论 6 515
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,745评论 3 399
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 168,561评论 0 360
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,782评论 1 298
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,798评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,394评论 1 310
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,952评论 3 421
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,852评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,409评论 1 318
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,483评论 3 341
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,615评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,303评论 5 350
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,979评论 3 334
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,470评论 0 24
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,571评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 49,041评论 3 377
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,630评论 2 359

推荐阅读更多精彩内容