nginx-1.12.2編譯安裝指導


nginx-1.12.2編譯安裝

  • 下載源碼包
  • 安裝
  • 安裝后配置

下載源碼包

下載地址:http://nginx.org/en/download.html

nginx-1.12.2:http://nginx.org/download/nginx-1.12.2.tar.gz


安裝

創建nginx worker 用戶

groupadd -r www
useradd -r -g www -s /sbin/nologin www
id www

安裝前,安裝編譯環境及依賴包

yum install -y gcc gcc-c++ pcre-devel openssl-devel 

編譯選項

./configure \
--prefix=/usr/local/nginx-1.12.2 \
--conf-path=/usr/local/nginx-1.12.2/etc/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=www \
--group=www \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--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-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--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' \
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' \

make
make install

安裝后配置

創建 nginx-1.12.2 到 nginx的鏈接

ln -s /usr/local/nginx-1.12.2 /usr/local/nginx
ls -l |grep nginx

創建配置文件存放目錄鏈接

ln -s /usr/local/nginx/etc /etc/nginx
ls -l /etc/|grep nginx
ls /etc/nginx/

配置nginx啟動項

ln -s  /usr/local/nginx/sbin/nginx /usr/sbin/
ls -l /usr/sbin/ |grep nginx
nginx -V

vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
 
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
 
[Install]
WantedBy=multi-user.target

編輯配置文件

vim /etc/nginx/nginx.conf

user www;

mkdir -p /var/cache/nginx/client_temp   # 創建緩存目錄

防火牆配置

firewall-cmd --add-port=80/tcp --permanent 
firewall-cmd --reload

啟動 nginx,並設置開機啟動

systemctl start nginx
systemctl enable nginx

測試

瀏覽器訪問 ip地址
或
curl -I <ip>

安裝配置nginx完成,之后還需要優化和配置虛擬主機。升級的時候,把新版本的安裝目錄鏈接到 /usr/local/nginx 上,再把配置文件拷貝到新版本的安裝目錄就 ok 了。

rm -f /usr/local/nginx   # 刪除原來的鏈接
ln -s /usr/local/nginx-<version> /usr/local/nginx  # 新建新版本的鏈接
\cp -r /usr/local/nginx-<old-version>/etc/* /usr/local/gninx/etc/   # 拷貝配置文件到新版本的相應目錄下

nginx -V  # 查看版本信息
systemctl restart nginx  # 重啟nginx服務 

有疑惑之處請發郵件到下面的郵箱。
2017-11-6 by achxku@163.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM