编译安装 nginx-1.13.12

参考:http://www.linuxe.cn/post-168.html

1、在安装Nginx之前需要确保系统里已经安装好相关环境:pcre库(提供正则表达式和Rewrite模块的支持)、zlib库(提供Gzip压缩)、openssl(提供ssl支持),如果没有安装的话,用Yum来安装这些依赖环境即可,不需要额外编译:

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

2、为Nginx创建好用户和组,后续编译会用上

groupadd nginx
useradd -s /sbin/nologin -g nginx nginx

3、配置、编译

./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gzip_static_module \
--with-http_stub_status_module
make && make install

4、

4、编译安装完成后会在指定的安装目录创建以下目录:

prefix/sbin :  Nginx的启动脚本,也可以用该脚本做一系列检查工作
prefix/conf :  配置文件存放的目录
prefix/logs :  日志文件目录
prefix/html :  默认的网页文件存放目录
/usr/ local /nginx/sbin/nginx  -t   #检查配置文件是否有错
/usr/ local /nginx/sbin/nginx  - v        #查看Nginx版本
/usr/ local /nginx/sbin/nginx  -V   #查看编译Nginx时的选项
 

3、编译安装Nginx,常用选项: 

--prefix=path:设置Nginx的安装路径,不写的话默认是在/usr/local/nginx
--sbin-path=path:设置Nginx的可执行文件路径,默认路径是prefix/sbin/nginx
--conf-path=path:设置Nginx配置文件路径,默认路径是prefix/conf/nginx.conf
--pid-path=path:设置Nginx pid文件路径,默认路径是prefix/logs/nginx.pid
--error-log-path=path:设置错误日志存放路径,默认路径是prefix/logs/error.log
--http-log-path=path:设置访问日志存放路径,默认路径是prefix/logs/access.log
--user=name:设置运行Nginx的用户,默认用户是nobody
--group=name:设置运行Nginx的用户组,默认用户组是nobody
  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_v2_module              enable ngx_http_v2_module
  --with-http_realip_module          enable ngx_http_realip_module
  --with-http_addition_module        enable ngx_http_addition_module
  --with-http_xslt_module            enable ngx_http_xslt_module
  --with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module
  --with-http_image_filter_module    enable ngx_http_image_filter_module
  --with-http_image_filter_module=dynamic
                                     enable dynamic ngx_http_image_filter_module
  --with-http_geoip_module           enable ngx_http_geoip_module
  --with-http_geoip_module=dynamic   enable dynamic ngx_http_geoip_module
  --with-http_sub_module             enable ngx_http_sub_module
  --with-http_dav_module             enable ngx_http_dav_module
  --with-http_flv_module             enable ngx_http_flv_module
  --with-http_mp4_module             enable ngx_http_mp4_module
  --with-http_gunzip_module          enable ngx_http_gunzip_module
  --with-http_gzip_static_module     enable ngx_http_gzip_static_module
  --with-http_auth_request_module    enable ngx_http_auth_request_module
  --with-http_random_index_module    enable ngx_http_random_index_module
  --with-http_secure_link_module     enable ngx_http_secure_link_module
  --with-http_degradation_module     enable ngx_http_degradation_module
  --with-http_slice_module           enable ngx_http_slice_module
  --with-http_stub_status_module     enable ngx_http_stub_status_module

5、Nginx主配置文件(/usr/local/nginx/conf/nginx.conf)详解:
nginx的配置文件里有很多“{}”包括起来的标签,其中main和events都是全局性标签,

每个主机都配置在server标签里

在server标签里的location标签是做匹配

Location标签的匹配规则:
~      #区分大小写的正则匹配,
~*    #不区分大小写的正则匹配
^~    #禁止正则表达式匹配,当匹配到这里后停止其他所有匹配
=      #精确匹配

未做任何配置的配置文件:

#user  nobody;    #默认运行Nginx的用户名
worker_processes  1;    #开启的进程数,通常和cpu个数相等
events {
    worker_connections  1024;    #每个进程的并发数
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;      #长连接超时时间为65秒

    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

猜你喜欢

转载自www.cnblogs.com/linuxws/p/9099667.html
今日推荐