day42综合架构网站服务篇

  • nginx服务程序目录结构

  • nginx服务搭建网站页面

1.nginx程序目录结构信息
/etc/logrotate.d/nginx —— 利用logrotate实现日志文件自动切割
/etc/nginx/nginx.conf —— 主配置文件
/etc/nginx/conf.d/default.conf —— 扩展配置文件
/etc/nginx/fastcgi_params —— nginx -接口方式 fastcgi
/usr/sbin/nginx —— 程序命令文件
/usr/share/nginx —— 站点目录将网站页面所有元素资源进行整合,分类规范管理
/var/log/nginx —— 保存程序日志文件信息(access.log / error.log)
/vat/cache/nginx —— 数据信息是否真正缓存
2.nginx配置文件

主配置文件:/etc/nginx/nginx.conf
 cat /etc/nginx/nginx.conf
    user  nginx;                                --- 指定worker进程管理用户(建议指定为虚拟用户)
    worker_processes  4;                        --- 指定worker进程数量  建议设置数值=CPU核数  or  建议设置数值=2*CPU核数
    error_log  /var/log/nginx/error.log warn;   --- 配置错误日志保存路径
    pid        /var/run/nginx.pid;              --- 配置程序pid文件保存路径
    以上信息: nginx主区域配置信息
    
    events {
        worker_connections  2048;               --- 定义一个worker进程连接数(并发)   总的并发连接数=worker_process*worker_connections < 系统打开文件数
    }
    http {
        include       /etc/nginx/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  /var/log/nginx/access.log  main;                                --- 配置日志保存路径
        sendfile        on;
        #tcp_nopush     on;
        keepalive_timeout  65;                                                      --- 是否开启长链接功能
        #gzip  on;
        include /etc/nginx/conf.d/*.conf;       --- 加载扩展配置文件 
    }
扩展文件配置信息:
  cat /etc/nginx/conf.d/default.conf 
  server {
        listen       80;                            --- 指定服务监听端口号 默认是80
        server_name  www.oldboy.com;                --- 配置网站域名信息
        location / {
            root   /html/;                          --- 站点目录信息
            index  index.html index.htm;            --- 指定首页文件  首页文件不存在,访问网站会报403错误
            error_page   404 500 502 503 504  /oldboy.jpg;    --- 优雅显示错误页面配置
        }
        
    }
补充说明:
    01. nginx进程信息
        master进程: 控制nginx服务运行状态   老板
        worker进程: 处理用户访问网站请求    员工
    02. nginx配置文件语法规范
        a 指令信息结尾必须有分号
        b 括号信息必须成对出现
        
    03. nginx配置区域说明:
        a 主区域配置    配置错误日志 进程信息 worker进程用户
        b 事件区域配置  配置worker进程连接数信息
        c HTTP区域      配置功能参数 优化有关系      
        d server区域    配置网站功能参数
        e location区域  
        f if区域        判断区域 

3.系统打开文件数
 系统运行起来会打开相应文件

echo '* - nofile 65535' >>/etc/security/limits.conf

/etc/security/limits.conf 是Linux 资源使用配置文件,用来限制用户对系统资源的使用
语法:     
[root@localhost~]# cat /etc/security/limits.conf
* soft nproc 65535      # 警告设定所有用户最大打开进程数为65535
* hard nproc 65535      # 严格设定所有用户最大打开进程数为65535
* soft nofile 65535     # 警告设定所有用户最大打开文件数为65535
* hard nofile 65535     # 严格设定所有用户最大打开文件数为65535**

表示要限制的用户,可以是:
    ① 用户名
    ② 组名(组名前面加'@'以区别用户名)
    ③ *(表示所有用户)

有两个值:

  ① soft 表示警告的设定,可以超过这个设定值,但是超过会有警告信息
  ② hard 表示严格的设定,必定不能超过这个设定的值**

表示可选的资源,如下:

   ① core:限制内核文件的大小
   ② data:最大数据大小
   ③ fsize:最大文件大小
   ④ memlock:最大锁定内存地址空间
   ⑤ nofile:打开文件的最大数目
   ⑥ rss:最大持久设置大小
   ⑦ stack:最大栈大小
   ⑧ cpu:以分钟为单位的最多CPU时间
   ⑨ nproc:进程的最大数目
   ⑩ as:地址空间限制
表示要限制的值

5.部署搭建一个简单静态页面

第一个里程:编写配置文件
  vim /etc/nginx/conf.d/www.conf
    server {
        listen        80;
        server_name   www.oldboy.com;
        root         /html/www;
        index        index.html
      }
   systemctl restart nginx
第二个里程:创建站点目录/编写首页文件
  mkdir -p /html/www
  [root@web02 www]# cat index.html 
    
        
        
        男士养生
        
        
        老男孩男士养生会所,联系方式
        
小红 17783240234
小兰 11238123709
小灵 12731273123
第三个里程:域名解析配置 本地hosts 10.0.0.8 www.oldboy.com

你可能感兴趣的:(day42综合架构网站服务篇)