首頁  >  文章  >  系統教程  >  原創:Centos 7 原始碼編譯安裝 Nginx 1.13

原創:Centos 7 原始碼編譯安裝 Nginx 1.13

PHPz
PHPz原創
2024-07-16 21:18:31749瀏覽

關於nginx的相關介紹我就不說了,既然你選擇nginx作為你的web伺服器,想必你多少也對nginx server有不同認知和理解,接下來我就直接安裝。

原创:Centos 7 源码编译安装 Nginx 1.13

先決條件

我使用的是centos7.3 64位元核心版系統,安裝配置nginx前必須安裝nginx依賴包,請查看;Centos 7編譯安裝php7.1之生產篇,並安裝前文開頭所提供的依賴包。此依賴元件包適用於Nginx任意版本。

新建網頁用戶和群組

$ /usr/sbin/groupadd www
$ /usr/sbin/useradd -g www www
$ ulimit -SHn 65535 //设置linux高负载参数
從官方下載Nginx以及OpenSSL

下載Nginx時有兩個版本:開發版和穩定版,如果用於生產就下載穩定版本,http://nginx.org/en/download.html (最好下載最新版本的穩定版,這樣會有bug修復以及新功能)我下載的是就是目前最新版本nginx-1.13.5。

$ cd /tmp
$ wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
$ tar zxvf openssl-1.1.0e.tar.gz
$ wget https://nginx.org/download/nginx-1.13.5.tar.gz
$ tar zxvf nginx-1.13.5.tar.gz
$ cd nginx-1.13.5
安裝Nginx

你可能會注意到有些文檔教程安裝nginx的時候,並未指派這麼多模組,(看起來好長),有的連模組和用戶都沒有指派,其實模組是根據自己的需要指派的, 如果想以後不麻煩,那就按照下面的模組指派就行了,其實這也算是全能的了,不然後期你需要什麼還得重新編譯進去,不是很麻煩,但也不省事。至於是否指派使用者群組,我堅決會讓你指派,這可關乎nginx配置的可用性和安全穩定。

$ ./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-pcre \
--with-openssl=/tmp/openssl-1.1.0e \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module \
$ make -j8 && make install //编译并安装
建立 systemctl 系統 N​​ginx 單元檔案

安裝完成後還需要開機自啟動,不然每次開機都需要手動,那豈不是太麻煩。

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

[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target 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
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP /usr/local/nginx/logs/nginx.pid
ExecStop=/bin/kill -s QUIT /usr/local/nginx/logs/nginx.pid
PrivateTmp=true

[Install]
WantedBy=multi-user.target
保存并退出。
加入開機自啟動並啟動Nginx
$ systemctl enable nginx.service
$ systemctl restart nginx.service
設定Firewalld防火牆
$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ firewall-cmd --reload
查看Nginx是否啟動成功
$ ss -ntlp

可以查看到nginx進程已經運行了。到此nginx安裝就完成了,可能你還會有疑問,nginx怎麼解析並支援php程式呢,別慌,下一篇文章中我會寫到。

以上是原創:Centos 7 原始碼編譯安裝 Nginx 1.13的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn