如果要使用FastDFS,請先安裝FastDFS再安裝nginx 避免不必要的麻煩
nginx源碼包下載(本教程採用1.16.0)(編譯模塊包含了fastDFS和ssl模塊)
http://nginx.org/en/download.html
官網自己下載 或者使用以下命令遠程下載
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
切換至安裝目錄
cd /usr/local
使用rz命令將包上傳至服務器
rz
安裝依賴庫
yum -y install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel
解壓安裝包
tar xzvf nginx-1.16.0.tar.gz
切換到nginx目錄
cd nginx-1.16.0
運行./configure
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/log/error.log --http-log-path=/usr/local/nginx/log/access.log --pid-path=/usr/local/nginx/pid/nginx.pid --lock-path=/usr/local/nginx/lock/nginx.lock --user=root --group=root --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/ngin --add-module=/usr/local/fastdfs-nginx-module/src --with-http_ssl_module --with-http_v2_module
編譯
make
安裝
make install
啓動ngixn
切換目錄: cd /usr/local/nginx/sbin
啓動: ./nginx
查看: ps -ef | grep nginx
測試訪問: 39.47.243.223
可能出現的問題和一些解決方案
問題:(缺少目錄)
nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
方案:
mkdir -p /var/tmp/nginx/client
問題:(不用管它,繼續執行make -install)
make[1]: Leaving directory /usr/local/nginx-1.12.1;
方案:
不用管
問題:
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
方案:
停止運行中的nginx kill -9 殺進程
修改nginx.pid生成目錄:
在conf中的nginx.conf中解開pid目錄地址
pid pid/nginx.pid;//換成自己的目錄地址
執行命令:
/usr/local/nginx/sbin/nginx -c/usr/local/nginx/conf/nginx.conf
然後再啓動
./nginx