Nginx 添加模块

基于源码安装

#下载nginx 最新稳定版本
wget http://nginx.org/download/nginx-1.14.0.tar.gz

#解压
tar -zxvf nginx-1.14.0.tar.gz

# 全部采用默认安装
./configure & make & make install  
make   & make install 

执行完成之后 nginx 运行文件 就会被安装在 /usr/local/nginx 下。

基于参数构建

./configure

模块更新

# 添加状态查查看模块
./configure --with-http_stub_status_module 

# 重新创建主文件
make

# 将新生成的nginx 文件覆盖 旧文件。
make install

# 查看是否更新成功 显示了 configure 构建参数表示成功
/usr/local/nginx/sbin/nginx -V

Nginx 常用命令

  • 重载配置文件
    nginx -s reload
  • 立刻停止服务
    nginx -s stop
  • 优雅的停止服务
    nginx -s quit
  • 重新开始记录日志文件
    nginx -s reopen

Nginx 进程模型

liu@liu-VirtualBox:/etc/nginx$ ps aux | grep nginx
root      2454  0.0  0.0 124976  1412 ?        Ss   07:22   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data  2455  0.0  0.1 125336  3180 ?        S    07:22   0:00 nginx: worker process
liu      27881  0.0  0.0 15984   1088 pts/4    S+   07:49   0:00 grep --color=auto nginx

master : 表示主进程
worker:表示工作进行

如何配置worker进程 ?修改nginx配置文件

user www-data;
# worker_processes auto;
# 配置2个worker进程
worker_processes 2;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

修改完成以后,我们可以使用 nginx -t 检查语法是否正确

liu@liu-VirtualBox:/etc/nginx$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

然后使用命令nginx-s reload 重新加载配置文件

然后我们再次查看进程数

liu@liu-VirtualBox:/etc/nginx$ ps aux | grep nginx
root      2454  0.0  0.2 125120  4180 ?        Ss   07:22   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 27940  0.0  0.1 125448  3288 ?        S    07:59   0:00 nginx: worker process
www-data 27941  0.0  0.1 125448  3288 ?        S    07:59   0:00 nginx: worker process
liu      27948  0.0  0.0  15984   940 pts/4    S+   07:59   0:00 grep --color=auto nginx

nginx 默认采用epoll事件模型

events {
        # 每个worker允许连接的客户端最大连接数
        worker_connections 768;
        # 默认采用epoll模型
        # multi_accept on;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容