美文网首页
Nginx整理

Nginx整理

作者: 水煮鱼又失败了 | 来源:发表于2020-05-21 08:38 被阅读0次

目录

[TOC]

1 安装

1.1 安装依赖项

yum install gcc pcre-devel zlib-devel

1.2 下载

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

1.3 安装

#生成Makefile文件
./configure
#编译
make
#安装
make install

安装成功后,nginx目录如下:

/usr/local/nginx

目录下结构如下:

conf html logs sbin

2 nginx操作命令

2.1 启动

/usr/local/nginx/sbin/nginx

启动后,可以查看系统中对应的线程:

[root@localhost sbin]# ps -ef |grep nginx
root      9708     1  0 08:41 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    9709  9708  0 08:41 ?        00:00:00 nginx: worker process

浏览器访问对应服务器的80端口地址(如http://localhost),网页显示如下内容,表示启动成功:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

2.2 重新加载配置文件

/usr/local/nginx/sbin/nginx -s reload

执行命令后,主进程校验配置文件有效性,并尝试应用新的配置,如成功,主进程将启动新的工作进程并向旧的工作进程发送关闭消息,旧进程收到消息后,不再接收新的连接请求,并继续为当前请求提供服务,直到所有请求都得到服务

如新配置存在问题,无法使用,则主进程将回滚更改并继续使用旧的配置。

总结:

执行重新加载命令,如加载失败,仍采用之前配置;如加载成功,则新的请求采用新的配置,之前未结束的请求,仍然采用之前的配置。

2.3关闭

命令需在启动nginx的用户下执行。

  • 强制关闭
/usr/local/nginx/sbin/nginx -s stop
  • 等待工作进程完成当前请求后,再关闭
/usr/local/nginx/sbin/nginx -s stop

2.4 校验配置文件

  • 校验配置文件
/usr/local/nginx/sbin/nginx -t

输出如下:

[root@localhost conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

  • 校验配置文件并输出
/usr/local/nginx/sbin/nginx -T

输出如下:

[root@localhost conf]# /usr/local/nginx/sbin/nginx -T
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

configuration file /usr/local/nginx/conf/nginx.conf:
......(以下省略,为配置文件内容)

3 配置

3.1 说明

nginx配置文件为核心部分,相当于一个微型语言。

配置文件分为命令配置块配置

  • 命令配置为一行,参数之间空格分开,以;结尾。
  • 块配置以{``}作为开始和结束。

nginx配置,存在配置的继承关系,如子块中没有配置,父块中配置了,子块中将继承父块中的配置。

每个块和命令存在以下结构关系:

...#全局块

events{#events块
    ...
}

http{#http块
    ...#http全局块
    server{
        ...#server全局块
        location [PATTERN] {#location块
            ...
        }
        location [PATTERN] {
            ...
        }
    }
    server{
        ...
    }
}


其中events块、http块有一个,server块、location块可有多个。

3.1 基本配置

  1. server块默认配置

注释掉原有配置文件中server块。新增

server {
        location / {
           root html;
           index index.html;
        }
    }

相关文章

  • nginx 2

    1 nginx 常用模块整理 nginx 常用模块整理1 http核心模块 ngx_http_core_modu...

  • Nginx整理

    目录 [TOC] 1 安装 1.1 安装依赖项 1.2 下载 1.3 安装 安装成功后,nginx目录如下: /u...

  • nginx知识整理

    方向代理: 负载均衡: 虚拟主机: nginx官网:http://nginx.org/en/download.ht...

  • Nginx错误整理

    1. 缺少ssl模块 当nginx.conf中使用了ssl相关指令时,报如下错误 那是因为安装nginx时未安装n...

  • nginx基本配置、负载均衡、常用操作

    整理了nginx的相关资料,包括 基本配置 负载均衡 常用操作命令 基本配置 nginx.conf,有注释http...

  • Django + nginx + uwsgi搭建博客 整理

    Django + nginx + uwsgi搭建博客 整理 标签(空格分隔):Python Django Blog...

  • ingress-nginx部署

    ingress-nginx 该ingress-nginx是自己整理的一个模版,以上版本在我的环境可以正常运行,如果...

  • nginx 安装

    操作系统:debian 7.0 整理时间:2016-10-20 nginx官方网站 Nginx官网提供了三个类型的...

  • docker搭建nginx整理

    DockerNginx.sh 内容 测试

  • Flask服务器部署:使用Docker+Gunicorn+gev

    摘要:Flask,gunicorn,nginx,docker,gevent,WSGI 整理一下Flask的部署相关...

网友评论

      本文标题:Nginx整理

      本文链接:https://www.haomeiwen.com/subject/cdfbohtx.html