码迷,mamicode.com
首页 > 其他好文 > 详细

nginx的安装

时间:2017-09-23 10:28:55      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:run   sse   serve   pen   ref   cte   ica   pre   str   

详见查看nginx.org

一、nginx安装

nginx安装方法有两种:

  • yum安装

测试安装系统 centos6.5 

yum源:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/6/$basearch/
gpgcheck=0
enabled=1

安装版本为最新版

  • 源码安装

 

 1 [root@mytestpc1 ~]# yum groupinstall -y "Development tools" "Server Platform Development"   ##安装开发组件
 2 [root@mytestpc1 ~]# yum install -y pcre-devel openssl-devel zlib-devel ##安装一些模块用到的包 安装pcre是为了支持rewrite,zlib是为了支持gzip压缩,openssl是为了支持https;
 3 [root@mytest4 sbin]# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_gzip_static_module
 4 [root@mytest4 sbin]# make && make install
 5 [root@mytest4 sbin]# cd /usr/local/nginx/sbin
 6 [root@mytest4 sbin]# ll
 7 total 5844
 8 -rwxr-xr-x 1 root root 5982777 Sep 22 20:08 nginx
 9 [root@mytest4 sbin]# ./nginx -t          ##可以通过nginx -t 查nginx是否安装正常
10 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
11 nginx: configuration file /etc/nginx/nginx.conf test is successful

 二、nginx相关配置

 可以查看nginx模板的默认配置:

 1 [root@mytest4 ~]# cat /etc/nginx/nginx.conf.default | grep -v -e "^[[:space:]]*#.*" -e "^[[:space:]]*$"
 2 worker_processes  1;                                    ##worker线程数
 3 events {
 4     worker_connections  1024;                ##每个worker的最大并发数
 5 }
 6 http {                              ##nginx是按照模块进行配置,http模块相关配置
 7     include       mime.types;
 8     default_type  application/octet-stream;
 9     sendfile        on;
10     keepalive_timeout  65;                  
11     server {                          server相关
12         listen       80;
13         server_name  localhost;
14         location / {                     
15             root   html;
16             index  index.html index.htm;
17         }
18         error_page   500 502 503 504  /50x.html;
19         location = /50x.html {
20             root   html;
21         }
22     }
23 }

main配置段:

  配置指令的类别:

    正常运行必备的配置:

    优化性能的配置:

    用于调试定位问题的配置:

    nginx配置可以使用变量:

  正常运行必备的配置:

    1、user USERNAME [GROUPNAME];
    指定运行worker进程的用户 和组,例如:
    user nginx nginx;s

    2、pid /path/to/pid_file;
    指定nginx的pid文件;

    3、worker_rlimit_nofile #;
    指定一个worker进程所能够打开的最大文件句柄数;

    4、worker_rlimit_sigpending #;
    指定每个用户能够发往worker的信号的数量;

  优化性能相关的配置:
    1、worker_processes #:   可以使用cpu隔离,系统使用一颗核心,其他的worker个使用一个核心,一个worker放在一个cpu上可以使缓存命中数更高。
    worker线程的个数;通常应该为物理CPU核心个数减1;可以是auto,auto的数量是cpu的核心数

    2、worker_cpu_affinity cpumask ...;    cpu的亲缘性绑定
    绑定worker进程至指定的CPU上;
      CPUMASK
      0001  第一颗cpu
      0010  第二
      0100  第三
      1000  第四
      例如:
      worker_cpu_affinity 0000 0001、0000 0010、0000 0100;  & worker_cpu_affinity auto     


    3、timer_resolution t;
    gettimeofday();

    4、worker_priority nice;  ## nice值越低优先级越高,nice值对应的是-20~19 对应的优先级是100~139
    -20, 19

  用于调试、定位问题:
    1、daemon [off|on]
    是否以守护进程方式启动nginx;默认都是

    2、master_process on|off;
    是否以master/worker模型来运行nginx; 正常是on,调试时off

    3、error_log /path/to/error_log level;
    错误日志文件及其级别;出于调试的目的,可以使用debug级别,但此级别只有在编译nginx时使用了--with-debug选项才有效;

  

 

  

 

nginx的安装

标签:run   sse   serve   pen   ref   cte   ica   pre   str   

原文地址:http://www.cnblogs.com/Nvax/p/7577125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!