Nginx学习笔记(安装)

一、为什么学习nginx

  1. 绝大多数互联网公司流量入口都选择nginx,这是为什么呢?究竟nginx相比于apache、tomcat有哪些优势?有人说nginx性能高;有人说nginx多线程省资源;还有人说nginx代码写的好?鄙人带着探索精神想求证真相。
  2. 好久没看C代码了,感觉有些生疏,Linux源码有些多,还是拿nginx这个相对的软柿子练练手。

二、Nginx安装

nginx官网 http://nginx.org,右侧选择download,选择stable version进行安装。 建议在Linux系统安装,因为公司服务器都是Linux(默认用户已安装gcc),鄙人环境Ubuntu,来来来搞起。

# 前置依赖
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install libssl-dev

tar -zxvf nginx-1.14.2.tar.gz
./configure --prefix=xxxx   # 安装nginx目标目录
make 
sudo make install

安装完包含conf、html、log和sbin几个目录,*_temp目前我也不知道作用,猜测是和缓存有关,这个问题我们先记下来,带着问题看代码会更有效率。
What?源码安装太繁琐?对nginx浅尝辄止可以参考如下,鄙人是想看源码,所以从源码安装,

sudo apt-get install nginx

三、Nginx命令

./sbin/nginx -h

nginx version: nginx/1.14.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /home/jiaxue/Software/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

不翻译大家自己看,多看一手资料有好处。有不理解的欢迎线下交流,一起学习,一起进步。微信(453478062)

# 启动
sudo ./sbin/nginx
ps -ef | grep nginx    # 检查进程是否存在

不放心的用户可以用浏览器再测试下,浏览器中输入127.0.0.1,看到 Welcome to nginx!字样
纯服务器用户可以用如下方法测试:

sudo apt-get install curl
curl localhost
# 返回
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
# 和nginx html目录index.html一致
# 停止
sudo ./sbin/nginx -s quit
# 或者
kill -15 进程号    #-9也可以,但是不推荐

四、后续安排

  1. nginx配置(基本配置 + 反向代理)
  2. 介绍事件模型
  3. 学习nginx源码

水了一篇,文笔粗糙,各位见谅。希望广交天下好友,一起学习一起进步。北京互联网从业多年,当过校招社招面试官,擅长大数据、流计算、风控(反作弊)、广告系统。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容