zoukankan      html  css  js  c++  java
  • ②nginx 配置文件说明

    nginx程序配置文件说明

    1)配置文件的结构
    nginx配置文件结构:
    1)核心配置部分 main 区域
    2)事件配置部分 event 区域
    3)网站配置部分 http 区域 指定网站功能参数
    4)主机配置区域 server 区域 指定每个网站信息(域名 站点目录 首页文件)
    5)location配置区域 指定网站特殊功能 匹配uri
    http server location扩展了解项
    http{}层下允许有多个server{}层 一个server层下允许有多个location
    http{}标签主要用来解决用户的请求与响应
    server{}标签主要用来响应具体的某一个网站
    location{}标签主要用于匹配网站具体URL路径
    准备工作:
    cp nginx.conf nginx.conf.default
    grep -v "^$" nginx.conf.default >nginx.conf
    cat /etc/nginx/nginx.conf

    =================核心模块===========
        user  nginx;                                   --- 指定worker进程管理用户
        worker_processes  1;                           --- 指定worker进程的数量    建议调整数量=服务器CPU核心数(2倍)
        error_log  /var/log/nginx/error.log warn;      --- 指定错误日志保存路径     及警告的类型
        pid        /var/run/nginx.pid;                 --- 指定程序pid文件保存路径
    
    ================事件模块===========
        events {
            worker_connections  1024;                  --- 一个worker进程的最大连接数   调整按照2的倍数  服务总的连接数=worker_processes*worker_connections<系统打开文件数
            use epool;
        }
    
    ================http核心模块===========
        http {
            include       /etc/nginx/mime.types;       --- 加载指定其它配置文件(媒体资源类型文件) 
            default_type  application/octet-stream;    --- 默认识别媒体类型  默认以下载的方式传输给浏览器  前提在mime.types类型中找不到此类型的文件
            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  /var/log/nginx/access.log  main;   --- 定义访问日志存储路径及日志的格式
            sendfile        on;                        --- 和nginx优化有关
            #tcp_nopush     on;                        --- 和nginx优化有关
            keepalive_timeout  65;                     --- 连接超时时间  默认单位秒
            #gzip  on;                                 --- 开启压缩传输方式
            include /etc/nginx/conf.d/*.conf;          --- 加载conf.d下面的所有.conf扩展配置文件
        }
    ================主机配置模块============
         server {
            listen       80;                    --- 指定服务监听信息  默认监听端口信息
            server_name  www.yangyijing.cn;        --- 指定网站域名信息
            location / {                        --- 匹配不同uri,进行不同的配置 ???
                root   /usr/share/nginx/html;   --- 指定站点目录路径
                index  index.html index.htm;    --- 指定首页文件信息
            }
            error_page   500 502 503 504  /oldboy.jpg;   --- 优雅显示错误信息
            location = /oldboy.jpg {                     --- 匹配指定50x.html的uri
                root   /html;                            --- 指定站点目录
            }
        }
    

    疑问解答:

    1. nginx程序worker进程是什么?
      master process:控制服务可以正常运行 老板
      worker process:处理用户访问请求 员工

    实践配置:

    cat blog.conf 
     server {
            listen       80;
            server_name  localhost;
            #charset koi8-r; #字符集
            access_log  /var/log/nginx/blog_access.log  main;  #登陆日志
            error_log   /var/log/nginx/blog_error.log;
            location / {
                root   /html/blog;
                index  index.php index.html index.htm;
            }
    
            location /test {
                root   /html/blog;
                index  index.html index.htm;
            }
    
            location ~ .php$ {
                root           /html/blog;  #站点目录
                fastcgi_pass   127.0.0.1:9000;  #php的文件  通过fasecgi接口传给php解析器
                fastcgi_index  index.php;  #没有指定php文件是 解析index.php文件
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
        }
    

    创建目录和数据信息:
    mkdir /html --- 放入oldboy.jpg图片

    本地域名解析:
    C:WindowsSystem32driversetchosts

    运维网站代码上线流程:

    第一个历程:编写修改配置文件
    
    	vim /etc/nginx/conf.d/www.conf
        server {
           listen       80;
           server_name  www.oldboy.com;
           location / {
               root   /html/www;
               index  index.html index.htm;
        }
        systemctl restart nginx	
    
    第二个历程:根据配置文件调整系统环境
    
    mkdir /html/www 
    
    第三个历程:将开发人员写的代码上传到站点目录  开发人员-- gitlab(版本控制服务)-- 运维人员
    
    将代码包放入站点目录---解压 
    代码更新,要进行备份(回退还原)
    

    第四个历程:确认域名解析

    aliyun进行域名配置
    

    第五个历程:修改调整数据库

    SQL语句
    

    第六个历程:访问网站进行测试

    1. 研究logrotate切割日志程序
    2. 如何优化系统打开文件数 查看ulimit -a lsof
    3. 总结笔记
  • 相关阅读:
    BootstrapTable表格数据左右移动功能遇到的问题(数据左右移动,列表拖拽排序,模糊查询列表数据定位)
    MVC校验
    线程
    验证码
    PublicLogic
    进程
    请求处理过程
    上传组件
    委托
    Global全局应用程序类
  • 原文地址:https://www.cnblogs.com/yangtao416/p/14631298.html
Copyright © 2011-2022 走看看