考慮到生產環節下,nginx的使用可能更多的須要人們去定製化一些配置(如nginx所使用的pcre版本、安裝路徑、log路徑等一些信息),因此,咱們更多的採用源代碼編譯的方式去安裝nginx進行使用。html
nginx編譯參數的解釋linux
轉自: http://my.oschina.net/indestiny/blog/220017(轉)nginx
啓動的時候出現:c++
./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory錯誤的話,解決方案轉自:http://www.cnblogs.com/cnsanshao/p/3652510.html,即執行:ln -s /usr/local/lib/libpcre.so.1 /lib64 便可! centos
ps:個人一些軟件的版本信息:(切換到root進行install)bash
常見錯誤以及解決方案dom
1. no acceptable C compiler found in $PATHspa
則說明缺乏GCC環境,安裝便可:yum install gcc.net
2. You need a C++ compiler for C++ supportcode
安裝環境便可:yum install -y gcc gcc-c++
pcre:pcre-8.37.tar.gz
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.37
./configure
make && make install
ln -s /usr/local/lib/libpcre.so.1 /lib64/
zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install
openssl-1.0.2d.tar.gz (時間稍微久點)
tar -zxvf openssl-1.0.2d.tar.gz
cd openssl-1.0.2d
./config
make && make install
pagespeed (看我的需求)
tar -zxvf headers-more-nginx-module.tar.gz
nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --without-http_referer_module --with-pcre=/data/soft/pcre-8.37 --with-zlib=/data/soft/zlib-1.2.8 --with-openssl=/data/soft/openssl-1.0.2d --add-module=/data/soft/headers-more-nginx-module
make && make install (過程稍微久點)
cd /usr/local/nginx/sbin
./nginx -t (檢測nginx是否安裝成功)
./nginx (啓動nginx)
netstat -ntlp | grep 80 (查看nginx的端口是否成功啓動)
訪問你目標主機的外網IP,出現了 『Welcome to nginx!』則說明OK!
./nginx -V ,能夠查看nginx ./configure的一些信息
若是須要從新安裝,從新 ./configure 開始便可
配置nginx.conf
防止直接用IP地址訪問nginx (若是作其它動做,自行配置便可)
server { listen 80 default_server; server_name _; rewrite ^/(.*) https://www.abc.com redirect; }
ps :
參考: