Nginx离线源码安装

1.官网下载源码文件:
2.解压文件:
tar xvf nginx-1.12.2.tar.gz
了解一下nginx源码文件结构:
contrib           --- geo2nginx模块
Configure       ---该文件包含编译Nginx所需的所有配置细节和参数。 执行该文件将创建一个Makefile。
conf              ---Nginx配置文件,如nginx.conf和fastcgi.conf。
src                ---nginx的源代码,html,邮件等
man              ---Nginx的所有手册页
html              ---网站根位置默认配置文件index.html和50x.html文件。
Auto              ---包含不同的配置选项,像那些将被默认安装模块的模块文件,选项文件,其中包括不同的配置选项,等等。

理解configure脚本的参数
Nginx Users and Groups:
命令参数
描述
--user=USER
指定Nginx运行的用户
--group=GROUP
指定Nginx运行的组
Nginx 配置目录设置:
命令参数
描述
--prefix=PATH
Nginx服务器路径,除配置和库以外的所有文件。默认路径是/usr/local/nginx,而基于软件包管理器的安装使用/etc/nginx目录。

--sbin-path=PATH
Nginx可执行文件路径,这个路径托管nginx可执行文件。

默认路径是/usr/local /nginx/sbin/nginx,而基于软件包管理器的安装使用/usr/sbin /nginx目录。
--conf-path=PATH
Nginx配置路径,这个路径将主机nginx.conf,mime.type和其他各种配置文件。

默认情况下,该文件位于/usr /local/nginx/conf /中,软件包管理器安装将文件托管在/ etc/nginx/中。

--pid-path=PATH
Nginx进程nginx.pid文件,这个文件将存储Nginx进程的进程ID。

默认情况下,该文件位于/usr/local/nginx/logs/,软件包管理器安装的使用路径是/var/run/。

--lock-path=PATH
Nginx锁定文件nginx.lock文件,该文件包含特定进程已经使用的资源的锁定信息。

默认情况下,该文件位于/usr/local/nginx/logs,软件包管理器使用路径/var /run/。

Nginx日志目录选项:
命令参数
描述
--error-log-path=PATH
Nginx服务器错误日志路径,该文件将包含将包含错误,警告和诊断错误输出的文件名。默认目录:/usr/loacl/nginx/logs/error.log。
--http-log-path=PATH
Nginx服务器访问日志路径,该文件将包含Nginx托管网站的HTTP请求日志详细信息。默认情况下,HTTP访问和错误日志文件目录是/usr /local /nginx /logs/,软件包管理器在/var/log /nginx/上安装日志文件。

--http-client-body-temp-path=PATH
HTTP请求的临时文件位置。 它拥有客户端请求的报文体。

--http-fastcgi-temp-path=PATH
HTTP FastCGI,uWSGI,SCGI应用程序的临时文件位置。 该位置存储从FastCGI,uWSGI和SCGI服务器接收到的数据的临时文件。

默认情况下,临时路径文件夹在/usr/ local / nginx / logs /下创建,软件包管理器配置/ var / cache / nginx /目录。

--http-uwsgi-temp-path=PATH
--http-scgi-temp-path=PATH


安装Nginx时可以启用的所有http模块:
Command Parameter
Description
--with-http_ssl_module
This module provides support for HTTPS websites; this module requires OpenSSL to be enabled.
--with-http_realip_module
This module is used to get the real IP address of the client that is specified in the HTTP header.
--with-http_addition_module
This module is a filter module that is used to add text before and after a response.
--with-http_sub_module
This module is a substitution filter, and it is used to replace one specified string by another.
--with-http_dav_module
This module is used to enable WebDAV feature for file management using PUT, DELETE, MKCOL, COPY, and MOVE methods.
--with-http_flv_module
This module enables pseudo-streaming functionality for flash video file.
--with-http_mp4_module
This module enables pseudo-streaming functionality for .mp4, .m4v, or .m4a files.
--with-http_gunzip_module
This module is used to decompress content for clients that do not a support gzip encoding method.
--with-http_gzip_static_module
This module allows sending precompressed files with the .gz filename extension.
--with-http_random_index_module
This module picks a random file in a directory to serve as an index file.
--with-http_secure_link_module
This module is used to authenticate the requested link using the hash to protect resource from unauthorized access.
--with-http_stub_status_module
This module provides access to basic status information.
--with-http_auth_request_module
This module implements client authorization based on response code.
--with-http_spdy_module
This module provides support for Googles SPDY protocol. This is now a deprecated and is replaced by the newer HTTP/2 module.
--with-http_xslt_module
This is a filter module that transforms XML responses using XSLT stylesheets.
--with-http_image_filter_module
This is a filter module that is used to process JPEG, GIF and PNG images.
--with-http_geoip_module
This module is used for geo-targeting, it looks for client IP and compares it with the precompiled MaxMind database.
--with-http_degradation_module
This module is used to serve a particular error message when the server faces a low memory issue.

禁用Nginx默认情况下启用模块:

Command Parameter
Description
--without-http_charset_module
Disables re-encoding Charset to another.
--without-http_gzip_module
Disables gzip compression module.
--without-http_ssi_module
Disable Server Side Include module.
--without-http_userid_module
Disables cookie-based client identification .
--without-http_access_module
Disables client IP address based access filtering.
--without-http_auth_basic_module
Disables HTTP Basic Authentication module that is used to validate user access.
--without-http_autoindex_module
Disables directory listing of the website.
--without-http_geo_module
Disables geo-module allowing you to define variables with values depending on the client IP address.
--without-http_map_module
Disables map module that is used to define map blocks.
--without-http_split_clients_module
Disables split testing module.
--without-http_referer_module
Disables blocking access to sites for requests with invalid “Referer” header.
--without-http_rewrite_module
Disables HTTP rewrite module.
--without-http_proxy_module
Disables HTTP proxy module used to redirect to another server.
--without-http_fastcgi_module
Disables FastCGI module.
--without-http_uwsgi_module
Disables uWSGI module.
--without-http_scgi_module
Disables SCGI module.
--without-http_memcached_module
Disables memcached module that is used to obtain responses from memcached server.
--without-http_limit_conn_module
Disables connection limit set as per the defined key rule.
--without-http_limit_req_module
Disables request processing limit set as per the defined key.
--without-http_empty_gif_module
Disables transferring single pixel transparent gif.
--without-http_browser_module
Disables identifying User Agent from request header field.
--without-http_upstream_hash_module
Disables HTTP load balancing method for server group where the client-server mapping is based on the hashed key value.
--without-http_upstream_ip_hash_module
Disables HTTP load balancing where requests are distributed across group of servers based on client IP address.
--without-http_upstream_least_conn_module
Disables HTTP load balancing where a request is passed to the server with the least number of active connections.
--without-http_upstream_keepalive_module
Disables cache for connections to upstream servers.
--without-mail_pop3_module
Disables POP3 module for mail server proxy.
--without-mail_imap_module
Disables IMAP module for mail server proxy.
--without-mail_smtp_module
Disabled SMTP module for mail server proxy .

优化模块,Nginx可用的不同优化参数:

Command Parameter
Description
--with-cc=PATH
Used to specify alternate location for C compiler.
--with-cpp=PATH
Used to specify alternate location for C preprocessor.
--with-cc-opt=OPTIONS
Used to add parameters that will be added to the CFLAGS variable.
--with-ld-opt=OPTIONS
Used to define additional parameters that will be used during linking.
--with-cpu-opt=CPU
Used to specify different processor architecture.

MD5 选项

Command Parameter
Description
--with-md5=DIR
Specifies the path to md5 library sources.
--with-md5-opt=OPTIONS
Used to specify additional build options for md5.
--with-md5-asm
Uses md5 assembler sources.

SHA1选项

Command Parameter
Description
--with-sha1=DIR
Specifies the path to sha1 library sources.
--with-sha1-opt=OPTIONS
Used to specify additional build options for sha1.
--with-sha1-asm
Uses sha1 assembler sources .

zlib选项

Command Parameter
Description
--with-zlib=DIR
Specifies path of the zlib libraries, used when using specific version of zlib libraries.
--with-zlib-opt=OPTIONS
Used to specify additional build options for zlib.
--with-zlib-asm=CPU
Uses zlib assembler sources that are optimized for Pentium or Pentiumpro CPU architecture.

OpenSSL选项

Command Parameter
Description
--with-openssl=DIR
Specifies path of the OpenSSL libraries, used when using specific version of OpenSSL libraries.
--with-openssl-opt=OPTIONS
Used to specify additional build options for OpenSSL.

Libatomic选项

Command Parameter
Description
--with-libatomic
Forces libatomic libraries.
--with-libatomic=DIR
Specifies path of the libatomic libraries, used when using specific version of libatomic libraries .

Other 选项

Command Parameter
Description
--without-http
Disables HTTP server.
--without-http-cache
Disables HTTP cache.
--with-threads
Enables thread pool support.
--with-file-aio
Enables support for asynchronous disk IO operations.
--with-ipv6
Enables ipv6 support.
--build=NAME
Sets the build name.
--builddir=DIR
Sets the build location.
--add-module=PATH
Used to add third-party modules during compiling Nginx. You will specify the path of the module in this parameter.
--with-debug
Enables debug logging.

3.安装前配置:

./configure 后面加上述你想要的参数,如果什么都加就是全部默认。

4.编译和安装:
make
make install

5.设置环境变量:

export PATH = /usr/local /nginx/sbin : $PATH
6.启动:
nginx
启动后测试访问80端口
7.设置自启动:
chkconfig --add nginx

chkconfig --level 345 nginx on

附件一个最简Nginx配置

[liucc@localhost conf]$ cat 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;

    upstream appnode {
                server 127.0.0.1:3002 weight=1;
                server 127.0.0.1:3000 weight=1;
                }

    server {
        listen       80;
        location / {
                proxy_pass http://appnode;
        }
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值