1.常用命令
查看版本号:
./nginx -v
 
启动nginx:在/usr/local/nginx/sbin 目录下执行 
./nginx
 
关闭nginx:在/usr/local/nginx/sbin 目录下执行
./nginx -s stop
 
重加载nginx:在/usr/local/nginx/sbin 目录下执行
./nginx -s reload
 
2.nginx配置
nginx的默认安装目录为:/usr/local/nginx;
nginx的主配置文件为:nginx安装目录中conf目录下的nginx.conf;
 
nginx.conf文件:
#user  nobody;
worker_processes  1;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    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  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    server {
        listen       80;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
 
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
}
 
 
可以看到nginx配置文件可以分为3部分:1】全局块;2】events块;3】http块;
 
1)全局块
从配置文件开始到 events 块之间的内容;
主要会设置一些影响 nginx 服务器整体运行的配置指令;
主要包括配置运行 Nginx 服务器的:
    用户(组)、
    允许生成的 worker process 数、
    进程 PID 存放路径、
    日志存放路径和类型
    以及配置文件的引入等。
 
例如:
worker_processes  1;
表示nginx可以支持的并发处理量为1;
这是 Nginx 服务器并发处理服务的关键配置,worker_processes 值越大,可以支持的并发处理量也越多,但是会受到硬件、软件等设备的制约;
 
2)events块
events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接;
常用的设置包括:
    是否开启对多 work process下的网络连接进行序列化;
    是否允许同时接收多个网络连接;
    选取哪种事件驱动模型来处理连接请求;
    每个 wordprocess 可以同时支持的最大连接数等;
 
例如:
events {
    worker_connections  1024;
}
表示work process支持的最大连接数为1024个;
 
3)http块
这算是 Nginx 服务器配置中最频繁的部分,代理、缓存和日志定义等绝大多数功能和第三方模块的配置都在这里。
注意:http 块也可以包括 http 全局块、 server 块。
 
1】http全局块
http 全局块配置的指令包括:
    文件引入、
    MIME-TYPE 定义、
    日志自定义、
    连接超时时间、
    单链接请求数上限等。
 
2】server 块
一个 server 块可以配置多个 location 块。
这块的主要作用是
    基于 Nginx 服务器接收到的请求字符串(例如 server_name/uri-string),对虚拟主机名称(也可以是 IP 别名)之外的字符串(例如 前面的 /uri-string)进行匹配,
    对特定的请求进行处理。
    地址定向、数据缓存
    和应答控制等功能,
    还有许多第三方模块的配置也在这里进行。
 
例如:
server {
        listen       80;
        server_name  localhost;
   
        location / {
            root   html;
            index  index.html index.htm;
        }
    }
listen表示监听的是80端口;
server_name 表示主机名称是localhost,因为是本地;
location /表示当访问的路径满足location后的正则表达式时做一些请求跳转;
 
 
 

nginx常用命令和配置的更多相关文章

  1. nginx实战操作(常用命令及配置)

    1. nginx介绍 2. nginx常用命令 验证配置是否正确: nginx -t 查看Nginx的详细的版本号:nginx -V 查看Nginx的简洁版本号:nginx -v 启动Nginx:st ...

  2. nginx常用命令及简单配置

    nginx常用命令 nginx -c /usr/local/nginx/conf/nginx.conf 启动nginx(windows下start nginx); nginx -s quit 停止ng ...

  3. 【Linux】nginx常用命令

    相关内容链接 Centos之安装Nginx及注意事项 [nginx]详细配置说明 nginx常用命令 [重新加载配置]sudo nginx -s reload [打开nginx配置]sudo vim ...

  4. Nginx系列一:正向代理和反向代理、Nginx工作原理、Nginx常用命令和升级、搭建Nginx负载均衡

    转自https://www.cnblogs.com/leeSmall/p/9351343.html 仅供个人学习 一.什么是正向代理.什么是反向代理 1. 正向代理,意思是一个位于客户端和原始服务器( ...

  5. nginx常用命令汇总

    nginx基础命令: sudo nginx // 开启nginx服务器 sudo nginx -s reload // 重启nginx服务器 sudo nginx -s stop // 关闭nginx ...

  6. Vim常用命令及配置方案

    Vim常用命令及配置方案   几句话 很久之前就接触到vim,初学那阵觉得vim很酷炫,但确实对新手不是很友好.我也就简单看了下基本操作就上手了,但又不是长期在vim下工作,这就导致了每一次重新使用v ...

  7. WebSphere MQ常用命令及配置

    WebSphere MQ常用命令及配置 (2012-06-23 23:09:16) 标签: mq命令 杂谈 分类: MQ [导读]WebSphere MQ常用命令及配置 一,队列管理命令 1,创建队列 ...

  8. nginx常用功能和配置

    nginx常用功能和配置 1.nginx常用功能和配置 1.1 限流 1.2 压力测试工具--Ab 1.2.1安装 1.2.2 测试 1.2.3 返回值 1.3 limit_conn_zone 1.4 ...

  9. nginx常用命令参数

    命令行参数: 常用命令: -c filename:设置配置文件. -t :不运行,而仅仅测试配置文件.nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件. -s :传递一个信 ...

随机推荐

  1. Redis 学习笔记(篇五):对象(RedisObject)

    Redis-对象 在以前的文章中,我们介绍了 Redis 用到的主要数据结构,比如简单动态字符串.双端链表.字典.压缩列表.整数集合. 然而 Redis 并没有直接使用这些数据结构来实现键值对的数据库 ...

  2. Spring实例化Bean三种方法:构造器、静态工厂、实例工厂

    Spring中Bean相当于java中的类,可以通过xml文件对bean进行配置和管理. 一.Bean的实例化: 构造器实例化.静态工厂实例化.实例工厂方式实例化. 目录: 构造器实例化: xml配置 ...

  3. INI配置文件格式解析

    INI配置文件有三要素parameters,sections和comments. 1.parameters 指一条配置,就像key = value这样的. 2.sections sections是pa ...

  4. HTTPS 简单学习

    1. HTTP缺点 使用明文通信,内容可能会被窃听: 通信加密:使用SSL和TLS: 内容加密: 不验证通信方的身份,因此可能会遭到伪装: SSL提供加密和证书: 无法证明报文的完整性,因此会遭到修改 ...

  5. 深入理解C++11 C3

    继承构造函数 class A { public: A(int i):m_i(i) {} A(double d, int i):m_d(d),m_i(i){} private: int m_i{0}; ...

  6. C++ 继承 - 在派生类中对基类初始化

    构造函数与基类的其他成员不同,不能被派生类继承,因此为了初始化基类中的成员变量,需要在派生类中调用基类的构造函数(即显式调用),如果派送类没有调用则默认调用基类的无参构造函数(即隐式调用). 显式调用 ...

  7. 用python打开文件夹的三种方式

    一.利用explorer.exe import os # 利用explorer.exe执行 start_directory = r'C:\代码\软件包' os.system("explore ...

  8. kubernetes 健康检查和初始化容器

    Pod-hook:postStart:1.$ $ vim preStart-hook.yaml---apiVersion: v1kind: Podmetadata:  name: hook-demo1 ...

  9. k8s组件通信或者创建pod生命周期

    Kubernetes 多组件之间的通信原理: apiserver 负责 etcd 存储的所有操作,且只有 apiserver 才直接操作 etcd 集群 apiserver 对内(集群中的其他组件)和 ...

  10. Excel2016 保存\复制 卡死问题解决

    遇到的问题: 工作中经常碰到一些Excel表, 复制一行, 再粘贴要等5s以上才能显示成功. 保存一下文档, 也会出现页面白屏卡死的情况, 经过网上多个帖子进行操作依旧无解, 最后找到了自己的方法得以 ...