zoukankan      html  css  js  c++  java
  • nginx编译安装

    nginx 编译安装与配置使用
    1、安装编译环境
    yum -y install gcc gcc-c++
    2、安装pcre软件包(使nginx支持http rewrite模块)
    yum install -y pcre pcre-devel
    3、安装openssl-devel(使nginx支持ssl)
    yum install -y openssl openssl-devel
    4、安装zlib
    yum install -y zlib zlib-devel
    5、创建用户nginx
    useradd nginx

    passwd nginx 

    6、安装nginx
    [root@localhost ~]# wget http://nginx.org/download/nginx-1.16.0.tar.gz

    [root@localhost ~]# tar xzf nginx-1.16.0.tar.gz -C /usr/local/

    [root@localhost ~]# cd /usr/local/nginx-1.16.0/

    [root@localhost nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --group=nginx -user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf -error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --httpclient-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --httpfastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lockpath=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --withhttp_gzip_static_module --with-pcre --with-http_realip_module --with-stream

    [root@localhost nginx-1.16.0]# make && make install

    7、修改配置文件/etc/nginx/nginx.conf

    # 全局参数设置

    user nginx; #指定用户

    worker_processes 4; #设置nginx启动进程的数量,一般设置成与逻辑cpu数量相同

    error_log logs/error.log; #指定错误日志

    worker_rlimit_nofile 10240; #设置一个nginx进程能打开的大文件数
    pid /var/run/nginx.pid; events { worker_connections 1024; #设置一个进程的大并发连接数 }

    # http 服务相关设置 http {

    include mime.types;

    default_type application/octet-stream; l

    og_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;                                                                          #是否调用sendfile函数输出文件,一般设置为on,若nginx是用来进行磁盘IO负载应用 时,可以设置为off,降低系统负载

    gzip on;                                                                               #是否开启gzip压缩,将注释去掉开启

    keepalive_timeout 65;                                                      #设置长连接的超时时间

    # 虚拟服务器的相关设置

    server { listen 80;                                                             #设置监听的端口

    server_name localhost;                                                  #设置绑定的主机名、域名或ip地址

    # charset koi8-r;                                                              # 设置编码字符

    charset utf-8;

    location / {

    root /var/www/nginx;                                                     #设置服务器默认网站的根目录位置,需要手动创建

    index index.html index.htm;                                            #设置默认打开的文档

    }

    error_page 500 502 503 504 /50x.html;                         #设置错误信息返回页面

    location = /50x.html {

    root html;                                                                      #这里的绝对位置是/usr/local/nginx/html

    }

    }

    nginx.conf的组成:nginx.conf一共由三部分组成,分别为:全局块、events块、http块。在http块中又包含http全局 块、多个server块。每个server块中又包含server全局块以及多个location块。在统一配置块中嵌套的配置快,各个之间 不存在次序关系。
    检测nginx配置文件是否正确
    [root@localhost ~]# /usr/local/nginx/sbin/nginx -t 

    [root@localhost ~]# mkdir -p /tmp/nginx

    [root@localhost ~]# mkdir /usr/local/nginx/logs
    10、启动nginx服务
    [root@localhost ~]# /usr/local/nginx/sbin/nginx

  • 相关阅读:
    poj 3666 Making the Grade
    poj 3186 Treats for the Cows (区间dp)
    hdu 1074 Doing Homework(状压)
    CodeForces 489C Given Length and Sum of Digits...
    CodeForces 163A Substring and Subsequence
    CodeForces 366C Dima and Salad
    CodeForces 180C Letter
    CodeForces
    hdu 2859 Phalanx
    socket接收大数据流
  • 原文地址:https://www.cnblogs.com/wyglog/p/12459311.html
Copyright © 2011-2022 走看看