1、解压nginx的gz包
tar -zxvf nginx-1.12.1.tar.gz 这里我选择安装在/usr/local/目录
2、初始化配置
cd /media/didi/nginx-1.12.1
./configure
如果是要使用ssl的话,执行
./configure --with-http_stub_status_module --with-http_ssl_module --with-stream
比较全的命令
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-stream --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC'
3、运行 make install 进行编译
编译完成后会发生成了/usr/local/nginx/目录
继续
4、nginx的常用命令
cd /usr/local/nginx/sbin
启动:./nginx
停止:./nginx -s stop
重启:./nginx -s reopen
执行./nginx -h 可以看到命令的帮助信息
5、config出现的问题及解决方法
第一个问题:
./configure: error: C compiler cc is not found
解决方法:
yum -y install gcc gcc-c++ autoconf automake make
第二个问题:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解决方案:
yum -y install pcre-devel
第三个问题:
./configure: error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib=<path> option.
解决方案:
yum install -y zlib-devel
第四个问题:
./configure: error: SSL modules require the OpenSSL library.You can either do not enable the modules, or install the OpenSSL libraryinto the system, or build the OpenSSL library statically from the sourcewith nginx by using --with-openssl=<path> option.
解决方案:
yum -y install openssl openssl-devel
第五个问题
./configure: error: the HTTP XSLT module requires the libxml2/libxsltlibraries. You can either do not enable the module or install the libraries.
解决方案:
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel
第六个问题
./configure: error: the HTTP image filter module requires the GD library.You can either do not enable the module or install the libraries.
解决方案:
yum install gd gd-devel
第七个问题
+ perl version: This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multiCan't locate ExtUtils/Embed.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).BEGIN failed--compilation aborted../configure: error: perl module ExtUtils::Embed is required
解决方案:
yum install perl-ExtUtils-Embed
第八个问题
./configure: error: the Google perftools module requires the Google perftoolslibrary. You can either do not enable the module or install the library.
解决方案:
yum install google-perftools google-perftools-devel
第九个问题
nginx: [emerg] getpwnam("nginx") failed
解决方案:
useradd nginx
第十个问题
nginx: [emerg] "proxy_timeout" directive is not allowed here in /usr/local/nginx/conf/include/ddm.conf:13
nginx: [emerg] "proxy_pass" directive is not allowed here in /usr/local/nginx/conf/include/ddm.conf:14
解决方案:
尝试写到stream{}模块中