官网
http://nginx.org

介绍

  • nginx是C语言编写的

  • 源码安装的流程(和C语言流程类似)

    • 编译生成.obj文件
    • 连接生成.exe文件
    • 运行.exe文件
  • nginx轻量化的一个原因可能是

    • 各部分是模块化的,需要使用某一块

      • 在编译的时候,添加相应参数
      • 没有添加的参数,对应模块就没有安装

安装nginx常见错误

  • Nginx: [error] open() "/usr/local/Nginx/logs/Nginx.pid" failed(2:No such file or directory)

解决方法:输入 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

反向代理

centos防火墙

  • 前提:centos7
systemctl start firewalld               # 开启防火墙
systemctl stop firewalld                # 关闭防火墙
systemctl status firewalld              # 查看防火墙
  • 停用防火墙或者防火墙开放80端口

nginx自动启动设置

源码安装nginx后,

nginx开机自动启动,需要配置一下

否则,重启服务器,nginx停止服务,网站不能访问

路径重写

问题

http://www.todo.gold/api/session

参考资料:https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite

在/usr/local/nginx/conf中的nginx.conf

location  /foo {rewrite /foo/(.*) /$1  break;proxy_pass         http://localhost:3200;proxy_redirect     off;proxy_set_header   Host $host;
}

参考上面的之后,我的修改

location  /api {rewrite /api/(.*) /$1  break;proxy_pass         http://localhost:3000;proxy_redirect     off;proxy_set_header   Host $host;
}

安装centos-nginx心得

别人是开发服务器,自己使用服务器,还经常报错

重点

  1. 配置configure参数设置
  2. 理解nginx.conf、nginx.conf.default
  3. 反向代理

LNMP环境搭建

Nginx源文件目录结构

mime.types.default文件内容

types {text/html                                        html htm shtml;text/css                                         css;text/xml                                         xml;image/gif                                        gif;image/jpeg                                       jpeg jpg;application/javascript                           js;application/atom+xml                             atom;application/rss+xml                              rss;text/mathml                                      mml;text/plain                                       txt;text/vnd.sun.j2me.app-descriptor                 jad;text/vnd.wap.wml                                 wml;text/x-component                                 htc;image/png                                        png;image/svg+xml                                    svg svgz;image/tiff                                       tif tiff;image/vnd.wap.wbmp                               wbmp;image/webp                                       webp;image/x-icon                                     ico;image/x-jng                                      jng;image/x-ms-bmp                                   bmp;application/font-woff                            woff;application/java-archive                         jar war ear;application/json                                 json;application/mac-binhex40                         hqx;application/msword                               doc;application/pdf                                  pdf;application/postscript                           ps eps ai;application/rtf                                  rtf;application/vnd.apple.mpegurl                    m3u8;application/vnd.google-earth.kml+xml             kml;application/vnd.google-earth.kmz                 kmz;application/vnd.ms-excel                         xls;application/vnd.ms-fontobject                    eot;application/vnd.ms-powerpoint                    ppt;application/vnd.oasis.opendocument.graphics      odg;application/vnd.oasis.opendocument.presentation  odp;application/vnd.oasis.opendocument.spreadsheet   ods;application/vnd.oasis.opendocument.text          odt;application/vnd.openxmlformats-officedocument.presentationml.presentationpptx;application/vnd.openxmlformats-officedocument.spreadsheetml.sheetxlsx;application/vnd.openxmlformats-officedocument.wordprocessingml.documentdocx;application/vnd.wap.wmlc                         wmlc;application/x-7z-compressed                      7z;application/x-cocoa                              cco;application/x-java-archive-diff                  jardiff;application/x-java-jnlp-file                     jnlp;application/x-makeself                           run;application/x-perl                               pl pm;application/x-pilot                              prc pdb;application/x-rar-compressed                     rar;application/x-redhat-package-manager             rpm;application/x-sea                                sea;application/x-shockwave-flash                    swf;application/x-stuffit                            sit;application/x-tcl                                tcl tk;application/x-x509-ca-cert                       der pem crt;application/x-xpinstall                          xpi;application/xhtml+xml                            xhtml;application/xspf+xml                             xspf;application/zip                                  zip;application/octet-stream                         bin exe dll;application/octet-stream                         deb;application/octet-stream                         dmg;application/octet-stream                         iso img;application/octet-stream                         msi msp msm;audio/midi                                       mid midi kar;audio/mpeg                                       mp3;audio/ogg                                        ogg;audio/x-m4a                                      m4a;audio/x-realaudio                                ra;video/3gpp                                       3gpp 3gp;video/mp2t                                       ts;video/mp4                                        mp4;video/mpeg                                       mpeg mpg;video/quicktime                                  mov;video/webm                                       webm;video/x-flv                                      flv;video/x-m4v                                      m4v;video/x-mng                                      mng;video/x-ms-asf                                   asx asf;video/x-ms-wmv                                   wmv;video/x-msvideo                                  avi;
}

mime.types文件内容

types {text/html                                        html htm shtml;text/css                                         css;text/xml                                         xml;image/gif                                        gif;image/jpeg                                       jpeg jpg;application/javascript                           js;application/atom+xml                             atom;application/rss+xml                              rss;text/mathml                                      mml;text/plain                                       txt;text/vnd.sun.j2me.app-descriptor                 jad;text/vnd.wap.wml                                 wml;text/x-component                                 htc;image/png                                        png;image/svg+xml                                    svg svgz;image/tiff                                       tif tiff;image/vnd.wap.wbmp                               wbmp;image/webp                                       webp;image/x-icon                                     ico;image/x-jng                                      jng;image/x-ms-bmp                                   bmp;application/font-woff                            woff;application/java-archive                         jar war ear;application/json                                 json;application/mac-binhex40                         hqx;application/msword                               doc;application/pdf                                  pdf;application/postscript                           ps eps ai;application/rtf                                  rtf;application/vnd.apple.mpegurl                    m3u8;application/vnd.google-earth.kml+xml             kml;application/vnd.google-earth.kmz                 kmz;application/vnd.ms-excel                         xls;application/vnd.ms-fontobject                    eot;application/vnd.ms-powerpoint                    ppt;application/vnd.oasis.opendocument.graphics      odg;application/vnd.oasis.opendocument.presentation  odp;application/vnd.oasis.opendocument.spreadsheet   ods;application/vnd.oasis.opendocument.text          odt;application/vnd.openxmlformats-officedocument.presentationml.presentationpptx;application/vnd.openxmlformats-officedocument.spreadsheetml.sheetxlsx;application/vnd.openxmlformats-officedocument.wordprocessingml.documentdocx;application/vnd.wap.wmlc                         wmlc;application/x-7z-compressed                      7z;application/x-cocoa                              cco;application/x-java-archive-diff                  jardiff;application/x-java-jnlp-file                     jnlp;application/x-makeself                           run;application/x-perl                               pl pm;application/x-pilot                              prc pdb;application/x-rar-compressed                     rar;application/x-redhat-package-manager             rpm;application/x-sea                                sea;application/x-shockwave-flash                    swf;application/x-stuffit                            sit;application/x-tcl                                tcl tk;application/x-x509-ca-cert                       der pem crt;application/x-xpinstall                          xpi;application/xhtml+xml                            xhtml;application/xspf+xml                             xspf;application/zip                                  zip;application/octet-stream                         bin exe dll;application/octet-stream                         deb;application/octet-stream                         dmg;application/octet-stream                         iso img;application/octet-stream                         msi msp msm;audio/midi                                       mid midi kar;audio/mpeg                                       mp3;audio/ogg                                        ogg;audio/x-m4a                                      m4a;audio/x-realaudio                                ra;video/3gpp                                       3gpp 3gp;video/mp2t                                       ts;video/mp4                                        mp4;video/mpeg                                       mpeg mpg;video/quicktime                                  mov;video/webm                                       webm;video/x-flv                                      flv;video/x-m4v                                      m4v;video/x-mng                                      mng;video/x-ms-asf                                   asx asf;video/x-ms-wmv                                   wmv;video/x-msvideo                                  avi;
}

nginx-configure参数配置

  • 首次安装nginx的时候,可以直接./configure。但是之后需要再编译配置

  • 参考材料:http://nginx.org/en/docs/configure.html

  • 输入命令的时候,写在一行

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
--prefix=/usr/local/nginx
--with-http_stub_status_module
--with-http_gzip_static_module
--with-http_realip_module
--with-http_sub_module
--with-http_sub_module
--with-http_ssl_module`
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_gzip_static_module --with-http_stub_status_module --with-file-aio --with-http_realip_module --with-http_ssl_module

配置方案1

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-pcre=/usr/local/src/pcre-8.44 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.1.1g

显示1

Configuration summary+ using PCRE library: /usr/local/src/pcre-8.44+ using OpenSSL library: /usr/local/src/openssl-1.1.1g+ using zlib library: /usr/local/src/zlib-1.2.11nginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/local/nginx/sbin/nginx"nginx modules path: "/usr/local/nginx/modules"nginx configuration prefix: "/usr/local/nginx/conf"nginx configuration file: "/usr/local/nginx/conf/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: "/usr/local/nginx/logs/error.log"nginx http access log file: "/usr/local/nginx/logs/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"

配置方案2

./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --modules-path=/usr/local/nginx/modules --with-http_ssl_module --with-http_v2_module --with-pcre=/usr/local/src/pcre-8.44 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.1.1g

全部参数

--prefix=path
--sbin-path=path                            #设置可执行文件名. 默认是:prefix/sbin/nginx
--modules-path=path
--conf-path=path                            #设置配置文件名(nginx.conf). 默认是:prefix/conf/nginx.conf
--error-log-path=path
--pid-path=path                             #设置存放进程ID的nginx.pid文件名.默认是:prefix/logs/nginx.pid
--lock-path=path
--user=name
--group=name
--build=name
--builddir=path--with-select_module
--without-select_module--with-poll_module
--without-poll_module--with-threads
--with-file-aio
--with-http_ssl_module                      #启用支持https协议,依赖OpenSSL库
--with-http_v2_module
--with-http_realip_module
--with-http_addition_module--with-http_xslt_module
--with-http_xslt_module=dynamic--with-http_image_filter_module
--with-http_image_filter_module=dynamic--with-http_geoip_module
--with-http_geoip_module=dynamic--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_auth_request_module
--with-http_random_index_module
--with-http_secure_link_module
--with-http_degradation_module
--with-http_slice_module
--with-http_stub_status_module
--without-http_charset_module
--without-http_gzip_module
--without-http_ssi_module
--without-http_userid_module
--without-http_access_module
--without-http_auth_basic_module
--without-http_mirror_module
--without-http_autoindex_module
--without-http_geo_module
--without-http_map_module
--without-http_split_clients_module
--without-http_referer_module
--without-http_rewrite_module
--without-http_proxy_module
--without-http_fastcgi_module
--without-http_uwsgi_module
--without-http_scgi_module
--without-http_grpc_module
--without-http_memcached_module
--without-http_limit_conn_module
--without-http_limit_req_module
--without-http_empty_gif_module
--without-http_browser_module
--without-http_upstream_hash_module
--without-http_upstream_ip_hash_module
--without-http_upstream_least_conn_module
--without-http_upstream_keepalive_module
--without-http_upstream_zone_module--with-http_perl_module
--with-http_perl_module=dynamic--with-perl_modules_path=path
--with-perl=path
--http-log-path=path
--http-client-body-temp-path=path
--http-proxy-temp-path=path
--http-fastcgi-temp-path=path
--http-uwsgi-temp-path=path
--http-scgi-temp-path=path
--without-http
--without-http-cache--with-mail
--with-mail=dynamic--with-mail_ssl_module
--without-mail_pop3_module
--without-mail_imap_module
--without-mail_smtp_module--with-stream
--with-stream=dynamic--with-stream_ssl_module--with-stream_realip_module--with-stream_geoip_module
--with-stream_geoip_module=dynamic--with-stream_ssl_preread_module
--without-stream_limit_conn_module
--without-stream_access_module
--without-stream_geo_module
--without-stream_map_module
--without-stream_split_clients_module
--without-stream_return_module
--without-stream_upstream_hash_module
--without-stream_upstream_least_conn_module
--without-stream_upstream_zone_module
--with-google_perftools_module
--with-cpp_test_module
--add-module=path
--add-dynamic-module=path
--with-compat
--with-cc=path
--with-cpp=path
--with-cc-opt=parameters
--with-ld-opt=parameters
--with-cpu-opt=cpu
--without-pcre
--with-pcre
--with-pcre=path                    #sets the path to the sources of the PCRE library.#注意是源代码的路径(解压出来的文件的路径),不是编译安装后的路径
--with-pcre-opt=parameters
--with-pcre-jit
--with-zlib=path                    #sets the path to the sources of the zlib library.#注意是源代码的路径(解压出来的文件的路径),不是编译安装后的路径
--with-zlib-opt=parameters
--with-zlib-asm=cpu
--with-libatomic
--with-libatomic=path
--with-openssl=path                 #sets the path to the OpenSSL library sources.#注意是源代码的路径(解压出来的文件的路径),不是编译安装后的路径
--with-openssl-opt=parameters
--with-debug

nginx-configure参数含义

依赖库 序号 configure参数 解释 默认是否添加 是否需要配置
1 –prefix=path 定义将保留服务器文件的目录。
此相同目录还将用于设置的所有相对路径 configure(库源路径除外)和nginx.conf配置文件中。
/usr/local/nginx默认情况下设置为目录。
2 –sbin-path=path 设置nginx可执行文件的名称。
此名称仅在安装期间使用。
默认情况下,文件名为 *prefix*/sbin/nginx
3 –modules-path=path 定义将在其中安装nginx动态模块的目录。
默认情况下使用*prefix*/modules目录。
4 –conf-path=path 设置nginx.conf配置文件的名称。
如果需要,可以通过在命令行参数中指定nginx来始终使用其他配置文件来启动它 。
默认情况下,文件名为 。 -c *file*``*prefix*/conf/nginx.conf
5 –error-log-path=path 设置主要错误,警告和诊断文件的名称。
安装后,可以始终nginx.conf使用error_log伪指令在配置文件中 更改文件名 。
默认情况下,文件名为 *prefix*/logs/error.log
6 –pid-path=path 设置nginx.pid将存储主进程的进程ID 的文件名。
安装后,可以始终nginx.conf使用pid伪指令在配置文件中 更改文件名 。
默认情况下,文件名为 *prefix*/logs/nginx.pid
7 –lock-path=path 为锁定文件的名称设置前缀。
安装后,可以始终nginx.conf使用lock_file伪指令在配置文件中 更改该值 。
默认情况下,值为 *prefix*/logs/nginx.lock
8 –user=name 设置非特权用户的名称,其凭据将由工作进程使用。
安装后,可以始终nginx.conf使用用户指令在配置文件中 更改名称 。
默认用户名是nobody。
9 –group=name 设置工作进程将使用其凭据的组的名称。
安装后,可以始终nginx.conf使用用户指令在配置文件中 更改名称 。
默认情况下,组名称设置为非特权用户的名称。
10 –build=name 设置一个可选的nginx构建名称。
11 –builddir=path 设置构建目录。
12 –with-select_module
13 –without-select_module 启用或禁用构建允许服务器使用该select()方法的模块。
如果平台似乎不支持更合适的方法(例如kqueue,epoll或/ dev / poll),则会自动构建此模块。
14 –with-poll_module
15 –without-poll_module 启用或禁用构建允许服务器使用该poll()方法的模块。
如果平台似乎不支持更合适的方法(例如kqueue,epoll或/ dev / poll),则会自动构建此模块。
16 –with-threads 启用线程池的使用 。
17 –with-file-aio 支持 在FreeBSD和Linux上使用 异步文件I / O(AIO)。
openssl 18 –with-http_ssl_module 启用构建将HTTPS协议支持添加 到HTTP服务器的模块的功能。
默认情况下未构建此模块。
需要OpenSSL库来构建和运行此模块。
19 –with-http_v2_module 支持构建一个模块,该模块提供对HTTP / 2的支持 。
默认情况下未构建此模块。
20 –with-http_realip_module 启用构建ngx_http_realip_module 模块的功能,
该 模块将客户端地址更改为在指定的标头字段中发送的地址。
默认情况下未构建此模块。
21 –with-http_addition_module 允许构建ngx_http_addition_module 模块,
该 模块在响应前后添加文本。
默认情况下未构建此模块。
22 –with-http_xslt_module
libxml2、libxslt 23 –with-http_xslt_module=dynamic 支持构建ngx_http_xslt_module 模块,
该 模块使用一个或多个XSLT样式表转换XML响应。
默认情况下未构建此模块。
该libxml2的和 的libxslt库需要构建和运行此模块。
24 –with-http_image_filter_module
25 –with-http_image_filter_module=dynamic 支持构建ngx_http_image_filter_module 模块,
该 模块可以转换JPEG,GIF,PNG和WebP格式的图像。
默认情况下未构建此模块。
26 –with-http_geoip_module
27 –with-http_geoip_module=dynamic 支持构建ngx_http_geoip_module 模块,
该 模块根据客户端IP地址和预编译的MaxMind数据库创建变量 。
默认情况下未构建此模块。
28 –with-http_sub_module 支持构建ngx_http_sub_module 模块,
该 模块通过将一个指定的字符串替换为另一个指定的字符串来修改响应。
默认情况下未构建此模块。
29 –with-http_dav_module 支持构建ngx_http_dav_module 模块,
该 模块通过WebDAV协议提供文件管理自动化。
默认情况下未构建此模块。
30 –with-http_flv_module 支持构建ngx_http_flv_module 模块,
该 模块为Flash Video(FLV)文件提供伪流服务器端支持。
默认情况下未构建此模块。
31 –with-http_mp4_module 支持构建ngx_http_mp4_module 模块,
该 模块为MP4文件提供伪流服务器端支持。
默认情况下未构建此模块。
32 –with-http_gunzip_module 支持为不支持“ gzip”编码方法的客户端构建ngx_http_gunzip_module 模块,
该 模块使用“ Content-Encoding: gzip” 解压缩响应。
默认情况下未构建此模块。
33 –with-http_gzip_static_module 支持构建ngx_http_gzip_static_module 模块,
该 模块支持发送.gz扩展名为“ ”的预压缩文件,而不是常规文件。
默认情况下未构建此模块。
34 –with-http_auth_request_module 允许构建ngx_http_auth_request_module 模块,
该 模块基于子请求的结果实现客户端授权。
默认情况下未构建此模块。
35 –with-http_random_index_module 支持构建ngx_http_random_index_module 模块,
该 模块处理以斜杠(’ /')结尾的请求,并在目录中选择一个随机文件作为索引文件。
默认情况下未构建此模块。
36 –with-http_secure_link_module 启用构建 ngx_http_secure_link_module 模块。
默认情况下未构建此模块。
37 –with-http_degradation_module 启用构建 ngx_http_degradation_module模块。
默认情况下未构建此模块。
38 –with-http_slice_module 支持构建ngx_http_slice_module 模块,
该 模块将请求拆分为子请求,每个子请求返回一定范围的响应。
该模块提供了更有效的大响应缓存。
默认情况下未构建此模块。
39 –with-http_stub_status_module 支持构建ngx_http_stub_status_module 模块,
该 模块提供对基本状态信息的访问。
默认情况下未构建此模块。
40 –without-http_charset_module 禁用构建ngx_http_charset_module 模块,
该 模块将指定的字符集添加到“ Content-Type”响应头字段中,并且可以将数据从一个字符集转换为另一个字符集。
zlib 41 –without-http_gzip_module 禁用构建可压缩 HTTP服务器响应的模块。
zlib库是构建和运行此模块所必需的。
42 –without-http_ssi_module 禁用构建 处理通过SSI(服务器端包含)命令的 ngx_http_ssi_module模块的响应。
43 –without-http_userid_module 禁用构建ngx_http_userid_module 模块,
该 模块设置适合客户端标识的cookie。
44 –without-http_access_module 禁用构建ngx_http_access_module 模块,
该 模块允许限制对某些客户端地址的访问。
45 –without-http_auth_basic_module 禁用构建ngx_http_auth_basic_module 模块,
该 模块允许通过使用“ HTTP基本身份验证”协议验证用户名和密码来限制对资源的访问。
46 –without-http_mirror_module 禁用构建ngx_http_mirror_module 模块,
该 模块通过创建后台镜像子请求来实现原始请求的镜像。
47 –without-http_autoindex_module 禁用构建 ngx_http_autoindex_module 模块,以处理以斜杠(’ /')结尾的请求,并在ngx_http_index_module模块找不到索引文件的情况下生成目录列表 。
48 –without-http_geo_module 禁用构建ngx_http_geo_module 模块,
该 模块创建的变量的值取决于客户端IP地址。
49 –without-http_map_module 禁用构建ngx_http_map_module 模块,
该 模块创建的变量的值取决于其他变量的值。
50 –without-http_split_clients_module 禁用构建ngx_http_split_clients_module 模块,
该 模块创建用于A / B测试的变量。
51 –without-http_referer_module 禁用构建ngx_http_referer_module 模块,
该 模块可以阻止对“ Referer”标头字段中具有无效值的请求的站点访问。
pcre 52 –without-http_rewrite_module 禁用构建允许HTTP服务器 重定向请求和更改请求URI的模块。
构建和运行此模块需要PCRE库。
53 –without-http_proxy_module 禁用构建HTTP服务器 代理模块。
54 –without-http_fastcgi_module 禁用构建 将请求传递到FastCGI服务器的 ngx_http_fastcgi_module模块。
55 –without-http_uwsgi_module 禁用构建 将请求传递到uwsgi服务器的 ngx_http_uwsgi_module模块。
56 –without-http_scgi_module 禁用构建 将请求传递到SCGI服务器的 ngx_http_scgi_module模块。
57 –without-http_grpc_module 禁用构建 将请求传递到gRPC服务器的 ngx_http_grpc_module模块。
58 –without-http_memcached_module 禁用构建ngx_http_memcached_module 模块,
该 模块从内存缓存服务器获取响应。
59 –without-http_limit_conn_module 禁用构建ngx_http_limit_conn_module 模块,
该 模块限制每个键的连接数,例如,单个IP地址的连接数。
60 –without-http_limit_req_module 禁用构建ngx_http_limit_req_module 模块,
该 模块限制每个密钥的请求处理速率,例如,来自单个IP地址的请求的处理速率。
61 –without-http_empty_gif_module 禁用构建发出单像素透明GIF的模块 。
62 –without-http_browser_module 禁用构建ngx_http_browser_module 模块,
该 模块创建的变量的值取决于“ User-Agent”请求标头字段的值。
63 –without-http_upstream_hash_module 禁用构建实现哈希 负载平衡方法的模块 。
64 –without-http_upstream_ip_hash_module 禁用构建实现ip_hash 负载平衡方法的模块 。
65 –without-http_upstream_least_conn_module 禁用构建实现了minimum_conn 负载平衡方法的模块 。
66 –without-http_upstream_keepalive_module 禁用构建一个模块来提供 对上游服务器连接的缓存。
67 –without-http_upstream_zone_module 禁用构建模块,该模块可以将上游组的运行时状态存储在共享内存 区域中。
68 –with-http_perl_module
69 –with-http_perl_module=dynamic 支持构建 嵌入式Perl模块。
默认情况下未构建此模块。
70 –with-perl_modules_path=path 定义一个目录,该目录将保留Perl模块。
71 –with-perl=path 设置Perl二进制文件的名称。
72 –http-log-path=path 设置HTTP服务器的主请求日志文件的名称。
安装后,可以始终nginx.conf使用access_log伪指令在配置文件中 更改文件名 。
默认情况下,文件名为 *prefix*/logs/access.log
73 –http-client-body-temp-path=path 定义用于存储包含客户端请求正文的临时文件的目录。
安装后,可以始终nginx.conf使用client_body_temp_path 指令在配置文件中 更改目录 。
默认情况下,目录名为 *prefix*/client_body_temp
74 –http-proxy-temp-path=path 定义一个目录,用于存储带有从代理服务器接收到的数据的临时文件。
安装后,可以始终nginx.conf使用proxy_temp_path 指令在配置文件中 更改目录 。
默认情况下,目录名为 *prefix*/proxy_temp
75 –http-fastcgi-temp-path=path 定义一个目录,用于存储包含从FastCGI服务器接收到的数据的临时文件。
安装后,可以始终nginx.conf使用fastcgi_temp_path 指令在配置文件中 更改目录 。
默认情况下,目录名为 *prefix*/fastcgi_temp
76 –http-uwsgi-temp-path=path 定义一个目录,用于存储包含从uwsgi服务器接收到的数据的临时文件。
安装后,始终可以nginx.conf使用uwsgi_temp_path 指令在配置文件中 更改目录 。
默认情况下,目录名为 *prefix*/uwsgi_temp
77 –http-scgi-temp-path=path 定义一个目录,用于存储带有从SCGI服务器接收到的数据的临时文件。
安装后,可以始终nginx.conf使用scgi_temp_path 指令在配置文件中 更改目录 。
默认情况下,目录名为 *prefix*/scgi_temp
78 –without-http 禁用HTTP服务器。
79 –without-http-cache 禁用HTTP缓存。
80 –with-mail
81 –with-mail=dynamic 启用POP3 / IMAP4 / SMTP 邮件代理服务器。
openssl 82 –with-mail_ssl_module 启用构建将 SSL / TLS协议支持添加 到邮件代理服务器的模块的功能。
默认情况下未构建此模块。
需要OpenSSL库来构建和运行此模块。
83 –without-mail_pop3_module 在邮件代理服务器中 禁用POP3协议。
84 –without-mail_imap_module 在邮件代理服务器中 禁用IMAP协议。
85 –without-mail_smtp_module 在邮件代理服务器中 禁用SMTP协议。
86 –with-stream
87 –with-stream=dynamic 支持构建 用于通用TCP / UDP代理和负载平衡的 流模块。
默认情况下未构建此模块。
openssl 88 –with-stream_ssl_module 支持构建一个模块,该模块 向流模块添加 SSL / TLS协议支持。
默认情况下未构建此模块。需要OpenSSL库来构建和运行此模块。
89 –with-stream_realip_module 启用构建ngx_stream_realip_module 模块的功能,
该 模块将客户端地址更改为PROXY协议标头中发送的地址。
默认情况下未构建此模块。
90 –with-stream_geoip_module
91 –with-stream_geoip_module=dynamic 支持构建ngx_stream_geoip_module 模块,
该 模块根据客户端IP地址和预编译的MaxMind数据库创建变量 。
默认情况下未构建此模块。
92 –with-stream_ssl_preread_module 支持构建ngx_stream_ssl_preread_module 模块,
该 模块允许从ClientHello 消息中提取信息, 而无需终止SSL / TLS。
默认情况下未构建此模块。
93 –without-stream_limit_conn_module 禁用构建ngx_stream_limit_conn_module 模块,
该 模块限制每个键的连接数,例如,单个IP地址的连接数。
94 –without-stream_access_module 禁用构建ngx_stream_access_module 模块,
该 模块允许限制对某些客户端地址的访问。
95 –without-stream_geo_module 禁用构建ngx_stream_geo_module 模块,
该 模块创建的变量值取决于客户端IP地址。
96 –without-stream_map_module 禁用构建ngx_stream_map_module 模块,
该 模块创建的变量值取决于其他变量的值。
97 –without-stream_split_clients_module 禁用构建ngx_stream_split_clients_module 模块,
该 模块创建用于A / B测试的变量。
98 –without-stream_return_module 禁用构建ngx_stream_return_module 模块,
该 模块向客户端发送一些指定的值,然后关闭连接。
99 –without-stream_upstream_hash_module 禁用构建实现哈希 负载平衡方法的模块 。
100 –without-stream_upstream_least_conn_module 禁用构建实现了minimum_conn 负载平衡方法的模块 。
101 –without-stream_upstream_zone_module 禁用构建模块,该模块可以将上游组的运行时状态存储在共享内存 区域中。
102 –with-google_perftools_module 允许构建 ngx_google_perftools_module 模块,以使用Google Performance Tools对nginx工作进程进行 性能分析。
该模块供nginx开发人员使用,
默认情况下未构建。
103 –with-cpp_test_module 启用构建 ngx_cpp_test_module模块。
104 –add-module=path 启用外部模块。
105 –add-dynamic-module=path 启用外部动态模块。
106 –with-compat 启用动态模块兼容性。
107 –with-cc=path 设置C编译器的名称。
108 –with-cpp=path 设置C预处理器的名称。
109 –with-cc-opt=parameters 设置将添加到CFLAGS变量的其他参数。
在FreeBSD下使用系统PCRE库时, --with-cc-opt="-I /usr/local/include" 应指定。
如果select()需要增加支持的文件数量,也可以在此处指定,例如: --with-cc-opt="-D FD_SETSIZE=2048"
110 –with-ld-opt=parameters 设置在链接期间将使用的其他参数。
在FreeBSD下使用系统PCRE库时, --with-ld-opt="-L /usr/local/lib" 应指定。
111 –with-cpu-opt=cpu 每个指定的CPU能够使建筑: pentiumpentiumpropentium3pentium4athlonopteronsparc32sparc64ppc64
pcre 112 –without-pcre 禁用PCRE库的使用。
pcre 113 –with-pcre 强制使用PCRE库。
pcre 114 –with-pcre=path 设置PCRE库源的路径。
需要从PCRE站点下载并分发库分发(版本4.4 — 8.43) 。其余的由nginx的./configure和完成 make
该库对于location指令中的正则表达式支持和 ngx_http_rewrite_module 模块是必需的 。
pcre 115 –with-pcre-opt=parameters 为PCRE设置其他构建选项。
pcre 116 –with-pcre-jit 使用“及时编译”支持(1.1.12,pcre_jit指令)构建PCRE库 。
zlib 117 –with-zlib=path 设置zlib库源的路径。
需要从zlib站点下载并分发库发行版(版本1.1.3-1.2.11) 。其余的由nginx的./configure和完成 make
ngx_http_gzip_module模块需要该库 。
zlib 118 –with-zlib-opt=parameters 为zlib设置其他构建选项。
zlib 119 –with-zlib-asm=cpu 使得能够使用指定的CPU中的一个优化的zlib汇编源程序: pentiumpentiumpro
libatomic_ops 120 –with-libatomic 强制使用libatomic_ops库。
libatomic_ops 121 –with-libatomic=path 设置libatomic_ops库源的路径。
openssl 122 –with-openssl=path 设置OpenSSL库源的路径。
openssl 123 –with-openssl-opt=parameters 为OpenSSL设置其他构建选项。
124 –with-debug 启用调试日志。

nginx-configure参数简书

序号 参数选项 基本解释 默认是否安装
1 –help 打印帮助信息
2 –prefix=PATH Nginx安装部署后的根目录 默认为/usr/local/nginx目录。
注意:这个目标的设置会影响其他参数中的相对目录。
例如,如果设置了–sbin-path=sbin/nginx,那么实际上可执行文件会被放到/usr/local/nginx/sbin/nginx中
3 –sbin-path=PATH 可执行文件的放置路径 /sbin/nginx
4 –conf-path=PATH 配置文件的放置路径 /conf/nginx.conf
5 –error-log-path=PATH error日志文件的放置路径。
error日志用于定位问题,可输出多种级别(包括debug调试级别)的日志。
它的配置非常灵活,可以在nginx.conf里配置为不同请求的日志并输出到不同的log文件中。
这里是默认的Nginx核心日志路径 /logs/error.log
6 –pid-path=PATH pid文件的存放路径。
这个文件里仅以ASC II码存放着Nginx master的进程ID,有了这个进程ID,在使用命令行(例如nginx -s reload)通过读取master进程ID向master进程发送信号时,才能对运行中的Nginx服务产生作用 /logs/nginx.pid
7 –lock-path=PATH lock文件的放置路径 /logs/nginx.lock
8 –user=USER 指定Nginx worker进程运行时所属的用户。
注意:不要将启动worker进程的用户设为root,在worker进程出问题时master进程要具备停止/启动worker进程的能力
9 –group=GROUP 指定Nginx worker进程运行时所属的组
10 –build=NAME configure执行时与编译期间产生的临时文件名称
11 –builddir=DIR configure执行时与编译期间产生的临时文件放置的目录,包括产生的Makefile、C源文件、目标文件、可执行文件等 /objs
12 –with-rtsig_module 使用rtsig module处理事件驱动
默认情况下,Nginx是不安装rtsig module的,
即不会把rtsig module编译进最终的Nginx二进制程序中
13 –with-select_module 使用select module处理事件驱动
select是Linux提供的一种多路复用机制,在epoll调用没有诞生前,例如在Linux 2.4及其之前的内核中,select用于支持服务器提供高并发连接
默认情况下,Nginx是不安装select module的,但如果没有找到其他更好的事件模块,该模块将会被安装
14 –without-select_module 不安装select module
15 –with-poll_module 使用poll module处理事件驱动 poll的性能与select类似,在大量并发连接下性能都远不如epoll。
默认情况下,Nginx是不安装poll
16 –without-poll_module 不安装poll module
17 –with-file-aio 使用AIO方式处理事件驱动 (IO异步大幅度提升性能,需要内核 2.6.22 以上的版本)
18 –with-ipv6 使Nginx支持IPv6
19 –with-https_ssl_module 安装https ssl module。
该模块使Nginx支持SSL协议,提供HTTPS服务。
注意:该模块的安装依赖于OpenSSL开源软件,即首先应确保已经在之前的参数中配置了OpenSSL需要安装 OpenSSL library yum install openssl-devel
20 –with-https_spdy_module 开启 ngx_https_spdy_module 模块。
是Google开发的基于TCP的应用层协议,用以最小化网络延迟,提升网络速度,优化用户的网络使用体验。
SPDY并不是一种用于替代HTTP的协议,而是对HTTP协议的增强
21 –with-https_realip_module 开启 ngx_https_realip_module 模块 。
此模块支持显示真实来源IP地址,
主要用于NGINX做前端负载均衡服务器使用。
22 –with-https_addition_module 开启 https addtion module。
该模块可以在返回客户端的HTTP包体头部或者尾部增加内容。
作为一个输出过滤器,支持不完全缓冲,分部分响应请求,游戏服务器不必安装,门户网站可以安装,有利于被搜索引擎收录页面信息。
23 –with-https_xslt_module 开启 ngx_https_xslt_module 模块
这个模块可以使XML格式的数据在发给客户端前加入XSL渲染,0.7.8后面版本才可以使用。
24 –with-https_image_filter_module 开启 ngx_https_image_filter_module 模块 。
这个模块将符合配置的图片实时压缩为指定大小(width*height)的缩略图再发送给用户,目前支持JPEG、PNG、GIF格式。
注意:这个模块依赖于开源的libgd库,在安装前确保操作系统已经安装了libgd,是nginx提供的集成图片处理模块,支持nginx-0.7.54以后的版本,
在网站访问量不是很高磁盘有限不想生成多余的图片文件的前提下可,就可以用它实时缩放图片,旋转图片,验证图片有效性以及获取图片宽高以及图片类型信息,由于是即时计算的结果,所以网站访问量大的话,不建议使用。
25 –with-https_geoip_module 开启 ngx_https_geoip_module 模块,
这个模块基于客户端的IP地址创建一些ngx_https_geoip_module变量,并与MaxMindGeoIP文件进行匹配,该模块仅用于0.7.63和0.8.6版本之后。 需要安装 yum install geoip-devel apt-get install geoip-bin geoip-database libgeoip-dev
26 –with-https_sub_module 开启 ngx_https_sub_module 。 该模块可以在Nginx返回客户端的HTTP响应包中将指定的字符串替换为自己需要的字符串
例如,在HTML的返回中,将替换为
27 –with-https_dav_module 开启 ngx_https_dav_module 模块。
这个模块可以让Nginx支持Webdav标准,如支持Webdav协议中的PUT、DELETE、COPY、MOVE、MKCOL等请求 默认情况下为关闭,需编译开启,如果开启WebDAV扩展动作模块,(可为文件和目录指定权限)
28 –with-https_flv_module 开启 ngx_https_flv_module 模块 ,
这个模块可以在向客户端返回响应时,对FLV格式的视频文件在header头做一些处理,使得客户端可以观看、拖动FLV视频
29 –with-https_mp4_module 开启 ngx_https_mp4_module 模块,
该模块使客户端可以观看、拖动MP4视频
30 –with-https_gunzip_module 开启 ngx_https_gunzip_module 模块,是一个过滤器,它为不支持“gzip”编码方法的客户端解压具有“Content-Encoding: gzip”头的响应。当希望存储压缩后的数据以节省空间和减少I/O开销,又不希望对那些不支持gzip压缩的客户端造成不利影响时, 此模块会派上用途。
31 –with-https_gzip_static_module 开启 ngx_https_gzip_static_module 模块 ,允许发送以“.gz”作为文件扩展名的预压缩文件,防止文件被重复压缩,以替代发送普通文件。如果采用gzip模块把一些文档进行gzip格式压缩后再返回给客户端,那么对同一个文件每次都会重新压缩,这是比较消耗服务器CPU资源的。
32 –with-https_auth_request_module 开启 ngx_https_auth_request_module 模块
33 –with-https_random_index_module 开启 ngx_https_random_index_module 模块 ,
该模块在客户端访问某个目录时,随机返回该目录下的索引文件
34 –with-https_secure_link_module 开启 ngx_https_secure_link_module ,
该模块提供一种验证请求是否有效的机制。
例如,它会验证URL中需要加入的token参数是否属于特定客户端发来的,以及检查时间戳是否过期(计算和检查要求所需的安全链接网址(防盗链))
35 –with-https_degradation_module 开启 ngx_https_degradation_module 模块,
该模块针对一些特殊的系统调用(如sbrk)做一些优化,允许在内存不足的情况下返回204或444码。
36 –with-https_stub_status_module 开启 ngx_https_stub_status_module 模块,
该模块可以让运行中的Nginx提供性能统计页面,获取相关的并发连接、请求的信息
37 –without-https_charset_module 关闭 https charset module。
这个模块可以将服务器发出的HTTP响应重编码
38 –without-https_gzip_module 关闭 ngx_https_gzip_module模块,
在服务器发出的HTTP响应包中,这个模块可以按照配置文件指定的content-type对特定大小的HTTP响应包体执行gzip压缩
39 –without-https_ssi_module 关闭 ngx_https_ssi_module模块,
该模块可以在向用户返回的HTTP响应包体中加入特定的内容,如HTML文件中固定的页头和页尾
40 –without-https_userid_module 关闭 ngx_https_userid_module模块,
这个模块可以通过HTTP请求头部信息里的一些字段认证用户信息,以确定请求是否合法
41 –without-https_access_module 关闭 访问模块,
这个模块可以根据IP地址限制能够访问服务器的客户端
42 –without-https_auth_basic_module 禁用基本的认证模块,
这个模块可以提供最简单的用户名/密码认证
43 –without-https_autoindex_module 禁用自动索引模块,该模块提供简单的目录浏览功能
44 –without-https_geo_module 禁用Geo模块,
这个模块可以定义一些变量,这些变量的值将与客户端IP地址关联,这样Nginx针对不同的地区的客户端(根据IP地址判断)返回不一样的结果, 例如不同地区显示不同语言的网页
45 –without-https_map_module 禁用Map模块,
这个模块可以建立一个key/value映射表,不同的key得到相应的value,这样可以针对不同的URL做特殊处理。
例如,返回302重定向响应时,可以期望URL不同时返回的Location字段也不一样
46 –without-https_split_clients_module 切割客户端IP,
该模块会根据客户端的信息,例如IP地址、header头、cookie等,来区分处理,nginx 的 Split Clients(切割客户端IP)的作用是使用 MurmurHash2 哈希算法对客户端的IP进行运算,得到一个32位的整数,这个数值范围从 0~4294967296,匹配不同的区间位置,得到不同的值赋予某个变量。最后根据这变量的不同,作不同的逻辑处理。
47 –without-https_referer_module 该模块可以根据请求中的referer字段来拒绝请求
48 –without-https_rewrite_module 禁用Rewrite模块,
该模块提供HTTP请求在Nginx服务内部的重定向功能,依赖PCRE库
49 –without-https_proxy_module 禁用代理模块。
该模块提供基本的HTTP反向代理功能
50 –without-https_fastcgi_module 禁用FastCGI模块。
该模块提供FastCGI功能
51 –without-https_uwsgi_module 禁用uwsgi模块。
该模块提供uWSGI功能
52 –without-https_scgi_module 禁用scqi模块。
该模块提供SCGI功能
53 –without-https_memcached_module 禁用Memcached模块。
该模块可以使得Nginx直接由上游的memcached服务读取数据,并简单地适配成HTTP响应返回给客户端
54 –without-https_limit_conn_module 禁用limit_conn_zone模块,
该模块针对某个IP地址限制并发连接数。例如,使Nginx对一个IP地址仅允许一个连接。
55 –without-https_limit_req_module 禁用Limit Requests模块。
该模块针对某个IP地址限制并发请求数
56 –without-https_empty_gif_module 禁用Empty Gif模块。
该模块可以使得Nginx在收到无效请求时,立刻返回内存中的1×1像素的GIF图片。这种好处在于,对于明显的无效请求不会去试图浪费服务器资源
57 –without-https_browser_module 禁用Browser 模块。
该模块会根据HTTP请求中的user-agent字段(该字段通常由浏览器填写)来识别浏览器
58 –without-https_upstream_hash_module 禁用Upstream模块。
该模块用于配置负载均衡结构
59 –without-https_upstream_ip_hash_module 禁用Upstream模块
该模块提供当Nginx与后端server建立连接时,会根据IP做散列运算来决定与后端哪台server通信,这样可以实现负载均衡
60 –without-https_upstream_least_conn_module 禁用Upstream模块中的 least 负载均衡算法
61 –without-https_upstream_keepalive_module 禁用Upstream模块中的 keepalive 负载均衡算法
62 –with-https_perl_module 需要安装 perl # yum install perl-ExtUtils-Embed | # apt-get install libperl-dev
63 –with-perl_modules_path=PATH perl module放置的路径。
只有使用了第三方的perl module,才需要配置这个路径
64 –with-perl=PATH perl binary 放置的路径。如果配置的Nginx会执行Perl脚本,那么就必须要设置此路径
65 –https-log-path=PATH access日志放置的位置。
每个HTTP请求到结束时都会记录 /logs/access.log
66 –https-client-body-temp-path=PATH 处理HTTP请求时如果请求的包体需要暂时存放到临时磁盘文件中,则把这样的临时文件放置到该路径下 /client_body_temp
67 –https-proxy-temp-path=PATH Nginx作为HTTP反向代理服务器时,上游服务器产生的HTTP包体在需要临时存放到磁盘文件时,这样的临时文件将放到该路径下 /proxy_temp
68 –https-fastcgi-temp-path=PATH Fastcgi所使用临时文件的放置目录 /fastcgi_temp
69 –https-uwsgi-temp-path=PATH uWSGI所使用临时文件的放置目录 /uwsgi_temp
70 –https-scgi-temp-path=PATH SCGI所使用临时文件的放置目录 /scgi_temp
71 –without-https 禁用HTTP服务
72 –without-https-cache 禁用HTTP 缓冲功能
73 –with-mail 开启邮件服务代理(mail server proxy)模块,支持POP3, IMAP4和SMTP。
该功能默认禁用
74 –with-mail_ssl_module 开启邮件代理服务对SSL的支持。
该功能默认禁用
75 –without-mail_pop3_module 在邮件代理下禁用POP3功能。
在开启邮件代理模块后该功能默认启用
76 –without-mail_imap_module 对邮件代理服务器禁用IMAP4模块,
在开启邮件代理模块后该功能默认启用
77 –without-mail_smtp_module 对于邮件代理服务器禁用SMTP模块,
在开启邮件代理模块后该功能默认启用
78 –with-google_perftools_module Google的针对nginx性能调优的工具,需要安装:yum install gperftools gperftools-devel
79 –with-cpp_test_module C预编译器测试模块
80 –add-module=PATH 当在Nginx里加入第三方模块时,通过这个参数指定第三方模块的路径
81 –with-cc=PATH C编译器的路径
82 –with-cpp=PATH C预编译器的路径
83 –with-cc-opt=OPTIONS 如果希望在Nginx编译期间指定加入一些编译选项,如指定宏或者使用-I加入某些需要包含的目录,这时可以使用该参数达成目的
84 –with-ld-opt=OPTIONS 最终的二进制可执行文件是由编译后生成的目标文件与一些第三方库链接生成的,在执行链接操作时可能会需要指定链接参数, –with-ld-opt就是用于加入链接时的参数。例如,如果我们希望将某个库链接到Nginx程序中,需要在这里加入–with-ld-opt=-llibraryName -LlibraryPath,其中libraryName是目标库的名称,libraryPath则是目标库所在的路径
85 –with-cpu-opt=CPU 指定CPU处理器架构,只能从以下取值中选择:pentium、pentiumpro、pentium3、pentium4、athlon、opteron、sparc32、sparc64、ppc64
86 –without-pcre 如果确认Nginx不用解析正则表达式,也就是说,nginx.conf配置文件中不会出现正则表达式,那么可以使用这个参数
87 –with-pcre 强制使用PCRE库
88 –with-pcre=DIR 指定PCRE库的源码位置,在编译Nginx时会进入该目录编译PCRE源码
89 –with-pcre-opt=OPTIONS 编译PCRE源码时希望加入的编译选项
90 –with-pcre-jit 编译PCRE库支持及时编译
91 –with-md5=DIR 指定SHA1库的源码位置,在编译Nginx时会进入该目录编译SHA1源码。
注意:OpenSSL中已经有了SHA1算法的实现。如果已经安装了OpenSSL,那么完全可以使用OpenSSL实现的SHA1算法
92 –with-md5-opt=OPTIONS 编译MD5源码时希望加入的编译选项
93 –with-md5-asm 使用MD5的汇编源码
94 –with-sha1=DIR 指定SHA1库的源码位置,在编译Nginx时会进入该目录编译SHA1源码。
注意:OpenSSL中已经有了SHA1算法的实现。如果已经安装了OpenSSL,那么完全可以使用OpenSSL实现的SHA1算法
95 –with-sha1-opt=OPTIONS 编译SHA1源码时希望加入的编译选项
96 –with-sha1-asm 使用SHA1的汇编源码
97 –with-zlib=DIR 指定zlib库的源码位置,在编译Nginx时会进入该目录编译zlib源码。如果使用了gzip压缩功能,就需要zlib库的支持
98 –with-zlib-opt=OPTIONS 编译zlib源码时希望加入的编译选项
99 –with-zlib-asm=CPU 指定对特定的CPU使用zlib库的汇编优化功能,
目前仅支持两种架构:pentium和pentiumpro
100 –with-libatomic 强制使用atomic库。
atomic库是CPU架构独立的一种原子操作的实现。它支持以下体系架构:x86(包括i386和x86_64)、PPC64、Sparc64(v9或更高版本)或者安装了GCC 4.1.0及更高版本的架构。
101 –with-libatomic=DIR atomic库所在的位置
102 –with-openssl=DIR 指定OpenSSL库的源码位置,在编译Nginx时会进入该目录编译OpenSSL源码。
注意:如果Web服务器支持HTTPS,也就是SSL协议,Nginx要求必须使用OpenSSL。
103 –with-openssl-opt=OPTIONS 编译OpenSSL源码时希望加入的编译选项
104 –with-debug 将Nginx需要打印debug调试级别日志的代码编译进Nginx。这样可以在Nginx运行时通过修改配置文件来使其打印调试日志,这对于研究、定位Nginx问题非常有帮助

nginx-ssl证书配置

  • cp命令和make命令的顺序,没有真正理解。不清楚是先cp,还是先make,最好应该先cp
  • make、make install的区别
  • 源码安装nginx的流程
    • 编译生成目标文件.obj
    • 连接生成可执行文件.exe

重新编译nginx

cd /usr/local/src/nginx-1.18.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# 这时在 /usr/local/src/nginx-1.18.0/objs下,生成一个nginx文件,这个文件类型应该是.obj文件
make # 这时在 /usr/local/src/nginx-1.18.0/objs下,生成一个文件,这个文件类型应该是.exe文件

复制 make 后的文件

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak # 备份一下nginx可执行文件# 把/usr/local/src/nginx/src/nignx-1.18.0/objs下的nginx.exe文件复制到sbin下
cp objs/nginx /usr/local/nginx/sbin/
# 或者
cp -rfp objs/nginx /usr/local/nginx/sbin/nginx
  • ssl
4181267_www.todo.gold.key
4181267_www.todo.gold.pem

nginx-systemctl配置

  • 设置nginx为系统服务
  • 安装完nginx,默认没有systemctl系列命令,需要进行如下配置

创建、编辑nginx.service

[root@web46 system]# cd
[root@web46 ~]# cd /usr/lib/systemd/system
[root@web46 system]# vim /usr/lib/systemd/system/nginx.service

粘入代码

[Unit]
Description=nginx-The High-performance HTTP Server       //描述服务
After=network.target remote-fs.target nss-lookup.target     //描述服务类别[Service]
Type=forking        //后台运行的形式
PIDFile=/usr/local/nginx/logs/nginx.pid     //PID文件的路径
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf     //启动准备
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf       //启动命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload        //重启命令
ExecStop=/usr/local/nginx/sbin/nginx -s stop            //停止命令
ExecQuit=/usr/local/nginx/sbin/nginx -s quit            //快速停止
PrivateTmp=true     //给服务分配临时空间[Install]
WantedBy=multi-user.target      //服务用户的模式

执行命令

[root@web46 system]# chmod +x nginx.service       //赋予该文件执行权限[root@web46 system]# systemctl daemon-reload        //在启动服务之前,需要先重载systemctl命令
[root@web46 system]# systemctl start nginx            //启动nginx服务
[root@web46 system]# netstat -ntulp |grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      17839/nginx: master

代码======================================================================

[root@web46 system]# cd
[root@web46 ~]# cd /usr/lib/systemd/system
[root@web46 system]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx-The High-performance HTTP Server
After=network.target remote-fs.target nss-lookup.target     [Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true[Install]
WantedBy=multi-user.target
[root@web46 system]# chmod +x nginx.service
  • 报错信息
    Job for nginx.service failed because the control process exited with error code. See “systemctl status nginx.service” and “journalctl -xe” for details.

nginx.conf.default文件内容

#user  nobody;
worker_processes  1;#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;
}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;#gzip  on;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;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}

nginx.conf文件内容

#user  nobody;
worker_processes  1;#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;
}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;#gzip  on;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;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server## server {#    listen       443 ssl;#   server_name  www.todo.gold;#    root html;#   ssl_certificate      cert/4181267_www.todo.gold.pem;#  ssl_certificate_key  cert/4181267.www.todo.gold.key;#  # ssl_session_cache    shared:SSL:1m;#  ssl_session_timeout  5m;# ssl_ciphers  ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:RC4;
#   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;#       ssl_prefer_server_ciphers  on;#      location / {#         root   html;#        index  index.html index.htm;#   }# }}

nginx.conf文件备份

# 多看文档,许多内容文档有详细描述
user  nobody;
worker_processes  1;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;
}# http模块
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;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;
#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;}# 这里是路径重写location /api {rewrite /api/(.*) /$1 break;proxy_pass         http://localhost:3000;proxy_redirect     off;proxy_set_header   Host $Host;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# 反向代理1,监听3000端口server {listen 80;server_name api.todo.gold;location / {proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host      $http_host;proxy_pass       http://127.0.0.1:3000;}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;
#    }#}# https配置,ssl证书# HTTPS server#server {listen       443 ssl;server_name  localhost;root html;index index.html index.htm;ssl_certificate      cert/*******_www.example.pem;ssl_certificate_key  cert/*******_www.example.key;# ssl_session_cache    shared:SSL:1m;ssl_session_timeout  5m;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_prefer_server_ciphers  on;location / {root   html;index  index.html index.htm;}}}

Nginx-centos阿里云源码安装

参考资料:阿里云-快速搭建LNMP环境

安装Nginx运行所需要的插件。

安装gcc

gcc是Linux下的编译器,它可以编译C、C++、Ada、Object C和Java等语言。

yum -y install gcc

安装pcre

pcre是一个perl库,Nginx的HTTP模块使用pcre来解析正则表达式。

yum install -y pcre pcre-devel

安装zlib

zlib是一个文件压缩和解压缩的库,Nginx使用zlib对HTTP数据包进行gzip压缩和解压。

yum install -y zlib zlib-devel

安装Nginx

wget http://nginx.org/download/nginx-1.17.10.tar.gz
tar -zxvf nginx-1.17.10.tar.gz
cd nginx-1.17.10
./configure
make && make install

启动Nginx

cd /usr/local/nginx/
sbin/nginx

Nginx-centos包安装

  • 前提条件:

    • centos版本:7.8
    • nginx版本:
  • 参考资料

    • 视频链接
  • yum包安装

安装nginx编译工具

  • 安装期间有提示,一律选y
yum install gcc-c++

安装nginx依赖库

  • pcre/zlib/openssl

  • 安装期间有提示,一律默认选y

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

下载解压nginx到/usr/local/

  • 进入/root目录
cd /root
wget https://nginx.org/download/nginx-1.13.9.tar.gz
tar -zxvf nginx-1.13.9.tar.gz -C /usr/local

编译并安装nginx

  • 进入nginx 1.13.9目录
cd nginx-1.13.9/
./configure
make
make install

开放linux的对外访问的端口

  • 在默认情况下,Linux不会开放端口号
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

启动nginx

  • 进入nginx/sbin目录
cd /usr/local/nginx/sbin
./nginx

安装成功

  • 出现如下图示,表示nginx

nginx命令

基本命令

#这些带./的命令,需要先切到这个目录 cd /usr/local/nginx/sbin

启动nginx

./nginx

经测试,这个不能用,没有这个命令

./nginx -s start

关闭nginx

./nginx - stop

重新加载配置文件

./nginx -s reload

待nginx进程处理任务完毕, 进行停止

./nginx -s quit

查看nginx的版本

./nginx -v

查看nginx安装的模块(大写V)

./nginx -V

检查nginx的配置文件是否有错误

./nginx -t

配置完nginx环境变量后,执行上面的命令,可以不需要先切到 cd /usr/local/nginx/sbin,并且不需要加.,如下

启动nginx, 这个命令不能连续执行2次

nginx

关闭nginx

nginx -s stop

重新载入配置文件

nginx -s reload

待nginx进程处理任务完毕, 进行停止

nginx -s quit

查看nginx的版本(小写v)

nginx -v

查看nginx安装的模块(大写V)

nginx -V

检查nginx的配置文件是否有错误

nginx -t

查看nginx的进程方式

ps -ef | grep nginx

查看nginx服务主进程的方式, 这个进程号和上面的进程号是一样的

cat nginx.pid

查看nginx的绝对路径

which nginx

定位到文件系统中可执行文件的位置

whereis nginx

这些命令需要配置之后,才可以使用 nginx.service

systemctl, 是Centos7中的, service是Centos6

systemctl status nginx
systemctl reload nginx
systemctl start nginx
systemctl stop nginx

查看nginx的 https监听是否启动(443端口)

netstat -ntpl

Nginx服务可接受的信号

信号 作用
TERM或INT 快速停止Nginx服务
QUIT 平缓停止Nginx服务
HUP 使用新的配置文件启动进程,之后平缓停止原有进程,也就是所谓的”平滑重启”
USR1 重新打开日志文件,常用于日志切割,在相关章节中会对此进一步说明
USR2 使用新版本的Nginx文件启动服务,之后平缓停止原有Nginx进程,也就是所谓的”平滑升级”
WINCH 平缓停止worker process,用于Nginx服务器平滑升级

向nginx服务主进程发送信号也有两种方法。

1, 使用nginx二进制文件

2, 是使用kill命令发送信号,其使用方法是:

Kill -9 PID

也可以通过发信号的方式:

使用TERM信号

[root@localhost nginx]# kill TERM 21094  (其中21094是master进程的pid,其中TERM可以换成INT 或QUIT)
-bash: kill: TERM: arguments must be process or job IDs
[root@localhost nginx]# ps -ef | grep nginx
root   21417 3019 0 08:16 pts/1  00:00:00 grep nginx

重启命令

[root@localhost nginx]# ./nginx -c nginx.conf
[root@localhost nginx]# ps -ef | grep nginx
root   21440   1 0 08:18 ?    00:00:00 nginx: master process ./nginx -c nginx.conf
nginx  21441 21440 0 08:18 ?    00:00:00 nginx: worker process
root   21445 3019 2 08:18 pts/1  00:00:00 grep nginx

Nginx命令表格

Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h this help
-v show version and exit
显示版本,并退出
-V show version and configure options then exit
显示版本和配置选项,并退出
-t test configuration and exit
检查Nginx服务器配置文件是否有语法错误,可以与-c联用,使输出内容更详细,这对查找配置文件中的语法错误很有帮助
-T test configuration, dump it and exit
测试配置,转储并退出
-q suppress non-error messages during configuration testing
在配置测试期间禁止显示非错误消息
-s signal send signal to a master process: stop, quit, reopen, reload
向主进程发送信号:停止、退出、重新打开、重新加载
-p prefix set prefix path (default: /usr/local/nginx/)
设置前缀路径(默认值:/usr/local/nginx/
-c filename set configuration file (default: conf/nginx.conf)
设置配置文件(默认:conf/nginx.conf)
-g directives set global directives out of configuration file
从配置文件中设置全局指令

nginx目录结构

[root@localhost ~]# tree /usr/local/nginx
/usr/local/nginx
├── client_body_temp
├── conf                             # Nginx所有配置文件的目录
│   ├── fastcgi.conf                 # fastcgi相关参数的配置文件
│   ├── fastcgi.conf.default         # fastcgi.conf的原始备份文件
│   ├── fastcgi_params               # fastcgi的参数文件
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types                   # 媒体类型
│   ├── mime.types.default
│   ├── nginx.conf                   # Nginx主配置文件
│   ├── nginx.conf.default
│   ├── scgi_params                  # scgi相关参数文件
│   ├── scgi_params.default
│   ├── uwsgi_params                 # uwsgi相关参数文件
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp                     # fastcgi临时数据目录
├── html                             # Nginx默认站点目录
│   ├── 50x.html                     # 错误页面优雅替代显示文件,例如当出现502错误时会调用此页面
│   └── index.html                   # 默认的首页文件
├── logs                             # Nginx日志目录
│   ├── access.log                   # 访问日志文件
│   ├── error.log                    # 错误日志文件
│   └── nginx.pid                    # pid文件,Nginx进程启动后,会把所有进程的ID号写到此文件
├── proxy_temp                       # 临时目录
├── sbin                             # Nginx命令目录
│   └── nginx                        # Nginx的启动命令
├── scgi_temp                        # 临时目录
└── uwsgi_temp                       # 临时目录

所有结尾为 default 的文件都是备份文件,其他未做注释的目录,为在生产环境中较少用到的目录。

nginx源码安装-环境变量设置

方法一:直接运行命令

export PATH=$PATH:/usr/local/webserver/php/bin
export PATH=$PATH:/usr/local/webserver/mysql/bin
# 使用这种方法,只会对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效,只是临时生效。

方法二:执行vi ~/.bash_profile修改文件中PATH一行,

vi ~/.bash_profile
# 将下面两条命令加入到PATH=$PATH:$HOME/bin一行之后
/usr/local/webserver/php/bin
/usr/local/webserver/mysql/bin
# 这种方法只对当前登录用户生效

方法三:修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码

vi /etc/profile
# 在文件末尾加上如下两行代码
PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin
export PATH
# 要是刚才的修改马上生效,需要执行以下代码
[root@CentOS ~]# source /etc/profile

实测

vi /etc/profile
# 在文件末尾加上如下两行代码
PATH=$PATH:/usr/local/nginx/sbin
export PATH
# 想要使刚才的修改马上生效,需要执行以下代码
[root@CentOS ~]# source /etc/profile
# 想要使刚才的修改马上生效,或者关闭xshell和重启服务器

Nginx-centos源码安装

环境

centos版本:7.8

gcc-g++版本:

zlib版本:1.2.11

pcre版本:8.44

openssl版本:1.1.1g

nginx版本:1.18.0

源码安装背景

生产环境下,由于包管理安装的nginx的方式可定义性不高,安装的版本也是较旧的版本,不能使用最新的特性。这时候可以选择源代码安装的方式,可以高度自定义。

参考链接:https://www.nginx.cn/install,但内容好像也不太完全正确

安装nginx编译工具

安装gcc-c++

gcc是Linux下的编译器,它可以编译C、C++、Ada、Object C和Java等语言。

yum install gcc gcc-c++

安装依赖库

安装pcre

pcre是一个perl库,Nginx的HTTP模块使用pcre来解析正则表达式。

cd /usr/local/src
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar -zxvf pcre-8.44.tar.gz
cd pcre-8.44
./configure
make
make install

下面这个暂时不行

cd /usr/local/src
wget https://ftp.pcre.org/pub/pcre/pcre2-10.35.tar.gz
tar -zxvf pcre2-10.35.tar.gz
cd pcre2-10.35
./configure
make
make install

安装zlib

zlib是一个文件压缩和解压缩的库,Nginx使用zlib对HTTP数据包进行gzip压缩和解压。

cd /usr/local/src
wget https://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib
make
make install

安装openssl

# 有的centos中默认带有,不需要安装,但是为了安装nginx时,方便构建./configure 指明openssl位置,有时还要安装
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxvf openssl-1.1.1g.tar.gz
cd openssl-1.1.1g
./config --prefix=/usr/local/openssl
make                                            # 这里大约需要3分钟
make install                                    # 这里大约需要2分钟

安装nginx

cd /usr/local/src
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
# configure参数配置
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --modules-path=/usr/local/nginx/modules --with-http_ssl_module --with-http_v2_module --with-pcre=/usr/local/src/pcre-8.44 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.1.1g
make                                            # 这里大约需要4分钟
make install

拓展

openssl

参考链接

  • https://www.openssl.org/docs/man1.1.1/man1/

介绍

openssl         # 进入openssl
openssl -v      # Error: '-v' is an invalid command
openssl -V      # Error: '-V' is an invalid command
openssl version # 查询openssl的版本

pcre

pcre2参考链接

  • https://pcre.org/current/doc/html/
介绍

pcre1:1997年发布,8.44

pcre2:2015年发布,10.35

zlib

nginx_centos相关推荐

  1. 创建支持nginx服务的docker镜像

    环境: [root@linux-node1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@linux-n ...

最新文章

  1. ​Android中如何使用Intent在Activity之间传递对象[使用Serializable或者Parcelable]
  2. NYOJ练习题 删除元素(二分查找)
  3. Struts2做下载
  4. Java程序通过批处理文件定时执行
  5. java lambda 表达式中的双冒号和箭头的用法 ::
  6. IDEA项目 let报错爆红
  7. 可用性目标概念化(摩西十戒)
  8. 13.C#的函数练习
  9. Java文件File类型转BASE64
  10. Xilinx平台SRIO介绍(六)SRIO收发测试
  11. keepalved(DR模式群集冗余备份)
  12. 使用Unity3D引擎制作塔防类游戏(一)
  13. 计算机网络吞吐量计算
  14. shell脚本——注释(单行注释 多行注释)
  15. 糖果(2019第十届蓝桥杯省赛C++A组I题) 解题报告(状压dp) Apare_xzc
  16. html 设置IE兼容模式
  17. 2018沈阳J How Much Memory Your Code Is Using?
  18. 天才制造者:独行侠、科技巨头和AI|深度学习崛起十年
  19. IGMPv1包结构及工作机制讲解
  20. 伺服电机的电子齿轮比如何确定?

热门文章

  1. Vue —— mockjs 模拟数据、轮播图插件 Swiper
  2. 哈工大计算机网络Mooc 第八章笔记(网络层(中))
  3. 利用特征值与特征向量求解弹性力学中的主应力与主平面问题
  4. php vip卡,vip.php
  5. ubuntu上强制关闭程序
  6. 计算机在职研究生是学历教育吗,计算机在职研究生有学籍吗
  7. 教孩子学习乘法和除法,我算是绞尽脑汁了
  8. 基于PHP+MYSQL的成绩查询系统(含源码)
  9. 云服务器添加交换分区
  10. 没“硬货”!不卖手机的苹果做起了信用卡和脱口秀