Linux源碼編譯安裝nginx

ps:一切從簡nginx

1、安裝所需環境:c++

    yum -y install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel web

2、下載及安裝nginxui

1.下載nginx:wget http://nginx.org/download/nginx-1.8.1.tar.gzorm

2.解壓nginx: tar -xzf nginx-1.8.1.tar.gzserver

3.添加用戶組:groupadd www、useradd -g www wwwip

3.編譯nginx:進入解壓以後的目錄執行 (這裏prefix爲安裝目錄)ssl

./configure \--user=www \--group=www \--prefix=/usr/local/nginx \--with-http_ssl_module \--with-http_stub_status_module \--with-http_realip_module \--with-threadsrem

4.安裝nginx:make && make installget

(安裝完成以後:make[1]: Leaving directory `/usr/local/nginx-1.8.1')  無傷大雅

5.驗證是否安裝成功:/usr/local/nginx/sbin/nginx -V

輸出:

nginx version: nginx/1.8.1

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

built with OpenSSL 1.0.2k-fips  26 Jan 2017

TLS SNI support enabled

configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads

3、配置nginx

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

添加以下:

[Unit]

Description=nginx - high performance web server

Documentation=http://nginx.org/en/docs/

After=network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.confExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true [Install]WantedBy=multi-user.target

執行:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

啓動nginx:

systemctl start nginx

設置開機啓動:

systemctl enable nginx

相關文章
相關標籤/搜索