RHEL/CentOS下編譯安裝Nginx

來源:互聯網
上載者:User

標籤:nginx   linux   web   rhel   

##下載nginx源碼:

wget http://nginx.org/download/nginx-1.7.8.tar.gztar -xv -f nginx-1.7.8.tar.gz -C /usr/local/src/


##安裝編譯環境和必須的組件:

yum groupinstall ‘Development Tools‘yum install pcre pcre-devel zlib zlib-devel openssl openssl-devel gcc gcc-c++ perl perl-devel perl-ExtUtils-Embed.noarch


##建立nginx使用者和組:

groupadd -r nginxuseradd -s /sbin/nologin -g nginx -c ‘Nginx web server‘ -r nginx


##建立用於存放臨時資料的目錄:

mkdir -p /var/tmp/nginx/tmp


##編譯安裝nginx:

./configure --prefix=/usr/local/nginx \#設定nginx的根目錄--conf-path=/etc/nginx/nginx.conf \#設定nginx設定檔的路徑--error-log-path=/var/log/nginx/error.log \#設定錯誤記錄檔的路徑--http-log-path=/var/log/nginx/access.log \#設定訪問日誌的路徑--http-client-body-temp-path=/var/tmp/nginx/tmp/client_body \#設定用戶端http請求的臨時檔案存放的位置--http-proxy-temp-path=/var/tmp/nginx/tmp/proxy \#nginx作為反向 Proxy時,上遊伺服器產生的http包體臨時存放的位置--http-fastcgi-temp-path=/var/tmp/nginx/tmp/fastcgi \#Fastcgi所使用臨時檔案的存放位置--http-uwsgi-temp-path=/var/tmp/nginx/tmp/uwsgi \#uWSGI 所使用臨時檔案的存放位置--http-scgi-temp-path=/var/tmp/nginx/tmp/scgi \#SCGI所使用臨時檔案的存放位置--with-http_ssl_module \#安裝http ssl模組。依賴於OpenSSL開源軟體--with-http_flv_module \#安裝http flv模組。以使用戶端可以觀看、拖動FLV視頻--with-http_mp4_module \#安裝http mp4模組。以使用戶端可以觀看、拖動MP4視頻--with-http_gzip_static_module \#安裝http gzip static模組。如果採用gzip模組把一些文檔進行gzip格式壓縮後再返回給用戶端,gzip static模組可以在做gzip壓縮前,先查看相同位置是否有已經做過gzip壓縮的.gz檔案,如果有,就直接返回。這樣就可以預先在伺服器上做好文檔的壓縮,給CPU減負--with-http_perl_module \#安裝http perl模組。使nginx支援perl指令碼--with-ld-opt="-Wl,-E" \#編譯最終的可執行檔時加入一些第三方庫。--with-mail \#安裝郵件伺服器反向 Proxy模組,使Nginx可以反向 ProxyIMAP、POP3、SMTP等協議--with-mail_ssl_module \#安裝mail ssl模組。該模組可以使IMAP、POP3、SMTP 等協議基於SSL/TLS協議之上使用。依賴於OpenSSL庫--with-http_stub_status_module \#安裝http stub status模組。該模組可以讓運行中的Nginx***能統計頁面,擷取相關的並發串連、請求的資訊--user=nginx \#指定Nginx worker進程運行時所屬的使用者。注意:不要將啟動worker進程的使用者設為root,在worker進程出問題時master進程要具備停止/啟動worker進程的能力--group=nginx#指定Nginx worker進程運行時所屬的組
make && make install

##安裝完後可再檢查一下安裝的一些資訊,如下:

# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.7.8

built by gcc 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC)

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/tmp/client_body --http-proxy-temp-path=/var/tmp/nginx/tmp/proxy --http-fastcgi-temp-path=/var/tmp/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/tmp/uwsgi --http-scgi-temp-path=/var/tmp/nginx/tmp/scgi --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_perl_module --with-ld-opt=-Wl,-E --with-mail --with-mail_ssl_module --with-http_stub_status_module --user=nginx --group=nginx

##測試一下nginx能否啟動(主要是看設定檔是否正確):

# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

##為了在使用nginx命令的時不用每次都輸入絕對路徑,可以通過修改PATH環境變數,:

# vim /etc/profile

添加:

PATH=${PATH}:/usr/local/nginx/sbin

##如果只想對本使用者生效可修改

# vim ~/.bash_profile

修改:

PATH=$PATH:$HOME/bin:/usr/local/nginx/sbin


本文出自 “銀凱的部落格” 部落格,請務必保留此出處http://yinkai.blog.51cto.com/3813923/1591128

RHEL/CentOS下編譯安裝Nginx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.