zoukankan      html  css  js  c++  java
  • 2.Nginx安装&配置文件

    本章内容:

      1.Nginx安装

      2.Nginx命令

      3.Nginx配置文件


    一、Nginx安装

    Step1:安装依赖包 gcc zlib pcre openssl

    yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

    Step2:安装Nginx

      1.下载jar包

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

       2.解压

    tar -xvf nginx-1.13.7.tar.g

      3.运行configure文件   (在解压后的文件nginx-1.13.7中)

    ./configure

       4.编译执行

    make && make install

       5. 进入  ./usr/local/nginx/conf/nginf.conf 可以进行配置,默认端口为80。(此步可忽略)

       6.进入  ./usr/local/nginx/sbin ,启动nginx

    ./nginx

    【成功访问页面默认端口80】

    【如果不能访问,需要关闭虚拟机防火墙】

    //查看开放的端口号
    firewall-cmd --list-all
    
    //设置开放的端口号
    firewall-cmd --add-service=http –permanent
    firewall-cmd --add-port=80/tcp --permanent
    
    //重启防火墙
    firewall-cmd –reload

    二、Nginx常用命令

     1 //进入 nginx 目录中,才能使用命令
     2 cd /usr/local/nginx/sbin
     3 
     4 //1、查看 nginx 版本号
     5 ./nginx -v 
     6 
     7 //2、启动 nginx
     8 ./nginx
     9 
    10 //3、停止 nginx
    11 ./nginx -s stop
    12 
    13 //4、重新加载 nginx(修改配置文件后重新加载,配置生效)
    14 ./nginx -s reload

     三、Nginx配置文件

     1. Nginx配置文件位置: /usr/local/nginx/conf/nginx.conf

     2. Nginx配置文件内容:

       分为三个部分:

      A.  全局块:配置服务器整体运行的配置指令

         从配置文件开始到 events 块之间的内容,主要会设置一些影响 nginx 服务器整体运行的配置指令,主要包括配置运行 Nginx 服务器的用户(组)、允许生成的 worker process 数,进程 PID 存放路径、日志存放路径和类型以及配置文件的引入等。

      B.  events块:影响Nginx服务器与用户的网络连接

       events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接,常用的设置包括是否开启对多 work process下的网络连接进行序列化,是否允许同时接收多个网络连接,选取哪种事件驱动模型来处理连接请求,每个 wordprocess 可以同时支持的最大连接数等。上述例子就表示每个 work process 支持的最大连接数为 1024.这部分的配置对 Nginx 的性能影响较大,在实际中应该灵活配置。

      C. http块:这算是 Nginx 服务器配置中最频繁的部分,代理、缓存和日志定义等绝大多数功能和第三方模块的配置都在这里。需要注意的是:http 块也可以包括 http 全局块、server 块。

        a.  http全局块:http 全局块配置的指令包括文件引入、MIME-TYPE 定义、日志自定义、连接超时时间、单链接请求数上限等。

        b.  server块:这块和虚拟主机有密切关系,虚拟主机从用户角度看,和一台独立的硬件主机是完全一样的,该技术的产生是为了节省互联网服务器硬件成本。每个 http 块可以包括多个 server 块,而每个 server 块就相当于一个虚拟主机而每个 server 块也分为全局 server 块,以及可以同时包含多个 locaton 块

     
    #user  nobody;
    worker_processes  1;//这是 Nginx 服务器并发处理服务的关键配//置,worker_processes 值越大,可以支持的并发处理量也越多,但是
    会受到硬件、软件等设备的制约
    
    #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;//每个 work process 支持的最大连接数为 1024。这部分的配置对 Nginx 的性能影响较大,
    在实际中应该灵活配置。
    } //==========================================模块分界线================================= 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; //---------------------------------------------http/server分界线---------------------- 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; "nginx.conf" 117L, 2656C
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    NFS与通配符
    yum管理RPM包与linux网络设置
    git常用命令总结——覆盖日常开发全操作
    inner join on会过滤掉两边空值的条件
    入园第一天
    P3750 [六省联考2017]分手是祝愿 题解
    CSP2021 爆零记
    CSP 前模板记录(黄题篇)
    对拍
    2021.10.20CSP模拟模拟赛 赛后总结
  • 原文地址:https://www.cnblogs.com/qmillet/p/12116928.html
Copyright © 2011-2022 走看看