當前位置:首頁 » 編程軟體 » nginx110編譯安裝

nginx110編譯安裝

發布時間: 2022-08-22 15:07:52

A. linux 怎麼安裝nginx

Centos7配置Nginx+php7Web服務

作者:JadeGlorious

1、安裝相應的擴展支持;

yuminstallgcc-c++
yuminstallpcrepcre-devel
yuminstallzlibzlib-devel
yuminstallopensslopenssl-devel
yum-yinstalllibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develmysqlpcre-devel
yum-yinstallcurl-devellibxslt-devel

集成至一行命令一次安裝
yum-yinstalllibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develmysqlpcre-develgcc-c++pcrepcre-develpcrepcre-developensslopenssl--develcurl-devellibxslt-devel

如有不能成功安裝的,單獨再安裝一次即可;
2、編譯安裝Nginx最新版本
//檢查是否已經安裝nginx

$find/-namenginx

//如果已經安裝nginx先卸載掉

$yumremovenginx

//進入習慣使用的下載目錄,下載想要使用的nginx版

$wgethttp://nginx.org/download/nginx-1.7.4.tar.gz

//解壓nginx安裝包

$tar-zxvfnginx-1.7.4.tar.gz

//進入解壓後的目錄

$cdnginx-1.7.4

//配置安裝信息,要載入什麼擴展,安裝到什麼目錄之類的
//使用--prefix參數指定nginx安裝的目錄,make、makeinstall安裝

$./configure$默認安裝在下載目錄

//指定目錄

$./configure--prefix=/usr/local/nginx//指定安裝在/usr/local/nginx

//編譯安裝

$make&&makeinstall

//檢查是否安裝成功

$whereisnginx

3、編譯安裝PHP7

//下載、解壓、進入目錄:

$wgethttp://downloads.php.net/~ab/php-7.0.6RC1.tar.gz
$tar-zxvfphp-7.0.6RC1.tar.gz$cdphp-7.0.6RC1

//配置安裝信息、擴展

$./configure--prefix=/usr/local/php--exec-prefix=/usr/local/php--bindir=/usr/local/php/bin--sbindir=/usr/local/php/sbin--includedir=/usr/local/php/include--libdir=/usr/local/php/lib/php--mandir=/usr/local/php/php/man--with-config-file-path=/usr/local/php/etc--with-mysql-sock=/var/run/mysql/mysql.sock--with-mhash--with-openssl--with-mysql=shared,mysqlnd--with-mysqli=shared,mysqlnd--with-pdo-mysql=shared,mysqlnd--with-gd--with-iconv--with-zlib--enable-zip--enable-inline-optimization--disable-debug--disable-rpath--enable-shared--enable-xml--enable-bcmath--enable-shmop--enable-sysvsem--enable-mbregex--enable-mbstring--enable-ftp--enable-gd-native-ttf--enable-pcntl--enable-sockets--with-xmlrpc--enable-soap--without-pear--with-gettext--enable-session--with-curl--with-jpeg-dir--with-freetype-dir--enable-opcache--enable-fpm--enable-fastcgi--with-fpm-user=nginx--with-fpm-group=nginx--without-gdbm--disable-fileinfo

//編譯檢查不通過,缺少什麼擴展安裝了重新檢測,通過後編譯安裝

$makeclean&&make&&makeinstall

maketest

配置文件
#cpphp.ini-development/usr/local/php/lib/php.ini
#cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
#cp/usr/local/php/etc/php-fpm.d/www.conf.default/usr/local/php/etc/php-fpm.d/www.conf#cp-R./sapi/fpm/php-fpm/etc/init.d/php-fpm

//安裝完成後修改nginx配置文件nginx.conf,添加對php的支持,指定項目目錄,完成後重啟nginx
//啟動php-fpm

#/etc/init.d/php-fpm

B. 怎麼編譯安裝nginx1.8.1

要編譯安裝Nginx,首先我們要安裝依賴包 pcre-devel 和 zlib-devel:
# yum install pcre-devel zlib-devel -y
程序默認是使用 nobody 身份運行的,我們建議使用 nginx 用戶來運行,首先添加Nginx組和用戶,不創建家目錄,不允許登陸系統
# groupadd nginx
# useradd -M -s /sbin/nologin -g nginx nginx

准備工作完成後就是下載編譯安裝Nginx了,可以從我提供的網盤下載,也可以去Nginx的官網下載。
首先解壓源碼包:
# tar xf nginx-1.4.4.tar.gz
然後 cd 到解壓後的目錄就可以執行 ./configure 了
# cd nginx-1.4.4
指定安裝目錄和運行時用的屬主和屬組,並啟用狀態監控模塊等
# ./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_mole \
--with-http_flv_mole \
--with-http_stub_status_mole \
--with-http_gzip_static_mole \
--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/nginx/scgi \
--with-pcre
等配置完成後就可以 make && make install 了
# make && make install
# mkdir /var/tmp/nginx/client/ -pv

等編譯安裝完成後在 /usr/local 下就會出現 Nginx 這個目錄了,進入這個目錄後發現目錄非常簡單。它的配置文件存放在 conf 目錄中,網頁文件存放在 html 中,日誌文件存放在 logs 中,sbin 目錄下只有一個可執行程序 "nginx"
接下來我們簡單的為它提供一個服務腳本吧!
# vim /etc/init.d/nginx
新建文件/etc/rc.d/init.d/nginx,內容如下:
#!/bin/bash
# chkconfig:235 85 15
# description: Nginx is an HTTP server
. /etc/rc.d/init.d/functions
start() {
echo "Start..."
/usr/local/nginx/sbin/nginx &> /dev/null
if [ $? -eq 0 ];then
echo "Start successful!"
else
echo "Start failed!"
fi
}

stop() {
if killproc nginx -QUIT ;then
echo "Stopping..."
fi
}

restart() {
stop
sleep 1
start
}

reload() {
killproc nginx -HUP
echo "Reloading..."
}

configtest() {
/usr/local/nginx/sbin/nginx -t
}

case $1 in
start)
start ;;
stop)
stop ;;
restart)
restart ;;
reload)
reload ;;
configtest)
configtest ;;
*)
echo "Usage: nginx {start|stop|restart|reload|configtest}"
;;
esac

之後給這個文件可執行許可權:
# chmod +x /etc/init.d/nginx
好了,現在可以使用 start,stop 這些參數控制Nginx服務了

由於腳本是我自己寫的,還有許多不盡人意的地方,歡迎大家修改和完善!
現在我們就試試啟動服務看看效果吧:
# service nginx start
記得關閉 SElinux 和 iptables 防火牆哦,
# service iptables stop
# setenforce 0
接下來就在瀏覽器中訪問你服務的IP看看效果吧!是不是出項了歡迎的字樣呢

接下來就研究下 Nginx 的配置文件吧!
# vim /usr/local/nginx/conf/nginx.conf
各項參數的意義如下:
worker_processes 1; 工作進程數量

error_log logs/error.log; 日誌文件位置
pid logs/nginx.pid; pid文件位置
worker_connections 1024; 沒進程的連接數
listen 80; 監聽埠
server_name localhost; 主機名
root html; 網站根目錄
index index.html index.htm; 網站索引頁
error_page 500 502 503 504 /50x.html; 訪問錯誤頁面
剩下的其他被注釋掉的代碼塊:
location ~ \.php$ { . . . . . . } 對PHP的支持,需要安裝PHP
server { . . . . . . } 添加server代碼塊能添加虛擬主機
剩下還有監聽443埠的超文本傳輸安全協議 HTTPS server 需要在編譯Nginx時添加ssl的支持

接下來我們試著添加一台虛擬主機吧,虛擬主機的添加可以基於埠,可以基於IP,也可以基於主機名,我們挨個來看看:
基於埠:
首先編輯配置文件,添加server代碼塊,記得要寫到http{ . . . . . . }這個大的代碼塊中。
server {
listen 8080;
server_name localhost;

location / {
root /var/www/html;
index index.html index.htm;
}
}
這樣就添加了一個監聽8080埠的服務,你也可以定義自己喜歡的埠哦。
接下來檢查下配置文件有沒有問題,如果最後一個單詞顯示successful就代表沒問題了,可以重新啟動Nginx了
# service nginx configtest
# service nginx restart
接下來就給第二個虛擬主機寫一個index吧!首先創建目錄
# mkdir -pv /var/www/html
# echo '<h1>Hi! This is 8080!</h1>' > /var/www/html/index.html
好了 接下來試著在瀏覽器中訪問訪問,記得第二個主機要加上埠訪問哦

現在試著用不同的IP建立虛擬主機吧!我們可以在一塊網卡上綁定多個IP地址的方式來實現
# ifconfig eth0:0 10.0.0.4/8
記得把IP換成你自己的哦!然後ifconfig看看是不是多出來一個網卡IP了呢
讓後繼續修改配置文件,這回要修改兩個地方,一個是原本自帶的站點的 listen 項,一個是自己添加的站點的 listen 項。
基於IP:
server {
listen 10.0.0.3:80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}

server {
listen 10.0.0.4:80;
server_name localhost;

location / {
root /var/www/html;
index index.html index.htm;
}
}
讓他們只監聽不同的IP,用相同的埠

接下來再瀏覽器上用不同的IP來訪問試試吧,及的還得重啟Nginx,先檢查一下,出現錯誤了看看哪裡配置的不對,然後就可以重啟了。
# service nginx congiftest
# service nginx restart
如果配置給網卡的第二個IP不想要了,把它停掉就可以了
# ifconfig eth0:0 down
再 ifconfig 看看是不是沒有了呢

現在試試用不同的主機名吧!也是企業用的最多的方式。我們把兩個站點的listen項都改為80,然後修改service_name項為定義的主機名
基於主機名:

server {
listen 80;
server_name ybmq.com;

location / {
root html;
index index.html index.htm;
}
}

server {
listen 80;
server_name zhzz.com;

location / {
root /var/www/html;
index index.html index.htm;
}
}

然後重啟Nginx吧!

可是我們在瀏覽器上怎麼通過域名訪問呢?要知道我們訪問 啊,qq 啊之類的是通過DNS伺服器的,難道我們還要配置一台DNS伺服器?其實不然,我們通過修改客戶機的 hosts 文件就可以了。hosts文件是一個本地的域名解析文件,我們要解析哪些域名只要把域名和對應的IP寫到一起就可以了。在Windows XP之後的系統中,這個文件位於:
C:\Windows\System32\drivers\etc\hosts
我們用文本編輯器打開,添加兩個相同的IP對應的兩個不同的主機名就可以了。
如下圖所示

如果你打開這個文件發現已經有很多IP地址了,可以直接在最後加入這兩行,也可以直接清空這個文件,不會有什麼問題的。這個文件的用途還可以屏蔽一些網站哦,只需要把網址對於的IP改為 127.0.0.1 也就是本地回環地址,瀏覽器查詢域名對應的IP時時先通過查詢這個文件的,如果查詢到了,不管對錯都不會訪問DNS伺服器了,所以我們給它一個錯誤的地址,那它一輩子也打不開被屏蔽掉的網站了。
好了 接下來就在瀏覽器中試試用用域名訪問你的兩個站點吧。
如果大家還用IP訪問會是什麼情況呢?我不說了,大家還是自己測試吧 哈哈o(^▽^)o

C. linux 下nginx模塊的安裝

安裝

第一步 下載並解壓Nginx壓縮

從Nginx官網下載Nginx,或者在Linux上執行wget http://nginx.org/download/nginx-1.10.1.tar.gz命令直接下載
解壓nginx-1.10.1.tar.gz文件:

tar zxvf nginx-1.10.1.tar.gz
1
1
第二步 配置

cd nginx-1.10.1
./configure --prefix=/usr/local/nginx
1
2
1
2
注意:
① 如果之前沒有安裝C compiler(C 編譯器),這一步將報如下錯誤信息:

xueliang@dev:~/download/nginx-1.10.1$ ./configure –prefix=/usr/local/nginx
checking for OS
+ Linux 4.2.0-27-generic x86_64
checking for C compiler … not found

./configure: error: C compiler cc is not found

xueliang@dev:~/download/nginx-1.10.1$
可以參考這篇文章安裝C compiler,然後繼續下面的操作

② 如果之前沒有安裝PCRE,這一步將報如下錯誤信息:

checking for PCRE library … not found
checking for PCRE library in /usr/local/ … not found
checking for PCRE library in /usr/include/pcre/ … not found
checking for PCRE library in /usr/pkg/ … not found
checking for PCRE library in /opt/local/ … not found

./configure: error: the HTTP rewrite mole requires the PCRE library.
You can either disable the mole by using –without-http_rewrite_mole
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre= option.

xueliang@dev:~/download/nginx-1.10.1$

③ 如果之前沒有安裝zlib,這一步將報如下錯誤信息:

checking for md5 in system md library … not found
checking for md5 in system md5 library … not found
checking for md5 in system OpenSSL crypto library … not found
checking for sha1 in system md library … not found
checking for sha1 in system OpenSSL crypto library … not found
checking for zlib library … not found

./configure: error: the HTTP gzip mole requires the zlib library.
You can either disable the mole by using –without-http_gzip_mole
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using –with-zlib= option.

xueliang@dev:~/download/nginx-1.10.1$

也可以跳過此步,執行默認安裝,--prefix的默認值為/usr/local/nginx,Nginx官網對此有說明:Building nginx from Sources

D. 如何重新編譯安裝一下nginx,讓它支持 sub

nginx編譯配置

最後的--add-mole就是引入的subs_filter模塊。
編譯並安裝nginx
在/etc/nginx/nginx.config中配置subs_filter

E. centos7怎麼編譯安裝nginx

安裝環境為:最小化安裝的centos7,關閉seliunx。
最小化安裝centos:
關閉selinux
sed –i 『s/SELINUX=enforcing/SELINUX=disabled/g』 /etc/selinux/config

開始安裝nginx1.7.8
創建群組
groupadd www
創建一個用戶,不允許登陸和不創主目錄
useradd -s /sbin/nologin -g www -M www
#下載最新版nginx
wget -C http://nginx.org/download/nginx-1.7.8.tar.gz
tar zxvf nginx-1.7.8.tar.gz
#編譯基本能運行的nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
make install

如果有錯誤提示:
./configure: error: C compiler cc is not found
解決方法:
yum install gcc gcc-c++

如果有錯誤提示:
./configure: error: the HTTP rewrite mole requires the PCRE library.
You can either disable the mole by using –without-http_rewrite_mole
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre=<path> option.
解決方法:
yum install pcre-devel

如果有錯誤提示:
./configure: error: SSL moles require the OpenSSL library.
You can either do not enable the moles, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using –with-openssl=<path> option.
解決方法:
yum install openssl-devel

以上錯誤提示依次解決後:再一次的運行
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
meke install

編譯參數解釋:
#指定運行許可權的用戶
--user=www
#指定運行的許可權用戶組
--group=www
#指定安裝路徑
--prefix=/usr/local/nginx
#支持nginx狀態查詢
--with-http_stub_status_mole
#開啟ssl支持
--with-http_ssl_mole
#開啟GZIP功能
--with-http_gzip_static_mole

因此要順利的通過nginx編譯安裝必須安裝的依賴關系有:
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel

2、在 centos7 中為nginx的啟動、重啟、重載配置添加腳本
nginx直接啟動的方法:
/usr/local/nginx/sbin/nginx

但是不是很方便,因此使用下面的腳本來控制nginx的啟動關閉重載更加合理一些。
編輯文件:vim /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.conf
ExecStart=/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

systemctl的一些使用方法:
systemctl is-enabled servicename.service #查詢服務是否開機啟動
systemctl enable xxx.service #開機運行服務
systemctl disable xxx.service #取消開機運行
systemctl start xxx.service #啟動服務
systemctl stop xxx.service #停止服務
systemctl restart xxx.service #重啟服務
systemctl reload xxx.service #重新載入服務配置文件
systemctl status xxx.service #查詢服務運行狀態
systemctl --failed #顯示啟動失敗的服務

因此,添加上面腳本後,centos7 中操作nginx的方法有
systemctl is-enabled nginx.service #查詢nginx是否開機啟動
systemctl enable nginx.service #開機運行nginx
systemctl disable nginx.service #取消開機運行nginx
systemctl start nginx.service #啟動nginx
systemctl stop nginx.service #停止nginx
systemctl restart nginx.service #重啟nginx
systemctl reload nginx.service #重新載入nginx配置文件
systemctl status nginx.service #查詢nginx運行狀態
systemctl --failed #顯示啟動失敗的服務

F. nginx編譯安裝需要哪些庫

如果有網的情況,不用管這些。進入你的nginx文件夾,進行以下操作:
通常至少需要以下庫:
pcre(正則) , gcc(C編譯器) , net-tools(使用netstat命令)。
一般有了上述的庫就能完成編譯,如果還不行,運行
./configure --prefix=你希望安裝到的目錄
命令,最下方提示error少了什麼庫,你就 yum -y install 庫名(錯誤的提示裡面)就可以自動下載安裝了。

G. nginx編譯安裝服務啟動腳本在哪

在你編譯是 --prefix=指定的目錄下有一個bin目錄,裡面有一個nginx啟動腳本,如果沒有指定,默認在/usr/local/nginx下,即/usr/local/nginx/sbin/nginx

H. 如何安裝nginx

Windows下安裝:
1.下載nginx壓縮包zip文件
2.解壓到一個目錄中
3.找到nginx.exe雙擊即可
一般需要對nginx.conf文件進行配置,如不配置,只能看到歡迎頁
Linux下安裝:
一、下載→編譯→安裝→啟動
1.下載nginx最新版
到官方網站上下載最新的tar.gz包
直接下載nginx的url為http://nginx.org/download/nginx-{version}.tar.gz,其中{version}為nginx的版本號
命令:[root@localhost ~]# wget http://nginx.org/download/nginx-1.9.14.tar.gz
2.解壓文件
[root@localhost ~]# tar -zvxf nginx-1.9.14.tar.gz
3.進入nginx解壓目錄
[root@localhost ~]# cd nginx-1.9.14
4.使用參數進行編譯,後面會給出編譯參數的具體解釋
[root@localhost nginx-1.9.14]# ./configure –prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/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=nginx –group=nginx –with-http_ssl_mole –with-http_realip_mole –with-http_addition_mole –with-http_sub_mole –with-http_dav_mole –with-http_flv_mole –with-http_mp4_mole –with-http_gunzip_mole –with-http_gzip_static_mole –with-http_random_index_mole –with-http_secure_link_mole –with-http_stub_status_mole –with-http_auth_request_mole –with-mail –with-mail_ssl_mole –with-file-aio –with-ipv6 –with-http_v2_mole
5.執行編譯過程
[root@localhost nginx-1.9.14]# make && make install
6.配置nginx.conf
7.啟動nginx
[root@localhost nginx-1.9.14]# nginx
二、編譯參數
–prefix=path
定義保存伺服器文件的目錄。這個目錄同時將作用於nginx.conf配置文件中配置的相對路徑(但不包括源碼庫的路徑)。默認值為/usr/local/nginx。
–sbin-path=path
設置nginx可執行文件的名稱,該名稱只在安裝期間使用。默認值是prefix/sbin/nginx
–conf-path=path
設置nginx.conf配置文件的名稱。如果需要,nginx可以使用不同的配置文件啟動,你可以通過命令行參數 -c file啟動。默認文件名為prefix/conf/nginx.conf
–pid-path=path
設置nginx.pid文件的名稱,nginx.pid用於存儲主進程的進程ID。安裝後,該文件名稱可以在nginx.conf的pid指令中修改。默認為prefix/logs/nginx.pid
–error-log-path=path
設置重要的錯誤、警告以及診斷文件的名字。安裝後,可以通過nginx.conf的error_log指令修改。默認為prefix/logs/error.log
–http-log-path=path
記錄主要請求日誌的名稱,安裝後通過access_log指令修改。默認為prefix/logs/access.log
–user=name
設置工作進程的用戶名,安裝後可以通過user指令修改。默認值為nobody
–group=name
設置工作進程的用戶組,安皇後可以通過user指令修改,默認與user相同。
–with-xxx_mole
安裝xxx模塊,這些模塊可以在nginx文檔中找到。
–without-xxx_mole
不安裝xxx模塊(有些模塊是默認安裝的,如果不想安裝,可以通過這個參數屏蔽),這些模塊可以在nginx文檔中找到。

I. 如何 編譯 ngx

一、必要軟體准備
1.安裝pcre

為了支持rewrite功能,我們需要安裝pcre

復制代碼代碼如下:
# yum install pcre* //如過你已經裝了,請跳過這一步

2.安裝openssl
需要ssl的支持,如果不需要ssl支持,請跳過這一步

復制代碼代碼如下:
# yum install openssl*

3.gzip 類庫安裝

復制代碼代碼如下:
yum install zlib zlib-devel

4.安裝wget
下載nginx使用,如果已經安裝,跳過這一步

復制代碼代碼如下:
# yum install wget

二、安裝nginx

1.下載

復制代碼代碼如下:
wget http://nginx.org/download/nginx-1.7.0.tar.gz

2.解壓

復制代碼代碼如下:

tar -zxvf nginx-1.7.0.tar.gz

3.編譯和安裝
執行如下命令:

復制代碼代碼如下:

# cd nginx-1.7.0
# ./configure --prefix=/usr/local/nginx-1.7.0 \
--with-http_ssl_mole --with-http_spdy_mole \
--with-http_stub_status_mole --with-pcre

–with-http_stub_status_mole:支持nginx狀態查詢
–with-http_ssl_mole:支持https
–with-http_spdy_mole:支持google的spdy,想了解請網路spdy,這個必須有ssl的支持
–with-pcre:為了支持rewrite重寫功能,必須制定pcre

最後輸出如下內容,表示configure OK了。

復制代碼代碼如下:

checking for zlib library ... found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx-1.7.0"
nginx binary file: "/usr/local/nginx-1.7.0/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx-1.7.0/conf"
nginx configuration file: "/usr/local/nginx-1.7.0/conf/nginx.conf"
nginx pid file: "/usr/local/nginx-1.7.0/logs/nginx.pid"
nginx error log file: "/usr/local/nginx-1.7.0/logs/error.log"
nginx http access log file: "/usr/local/nginx-1.7.0/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
# make //確定你的伺服器有安裝make,如果沒有安裝請執行yum install make

# make install

三、啟動、關閉、重置nginx
啟動:直接執行以下命令,nginx就啟動了,不需要改任何配置文件,nginx配置多域名虛擬主機請參考後續文章.

復制代碼代碼如下:
/usr/local/nginx-1.7.0/sbin/nginx

試試訪問:直接使用curl命令來讀取web信息

復制代碼代碼如下:

[root@ns conf]
# curl -s http://localhost | grep nginx.com
nginx.com.

關閉:

復制代碼代碼如下:
/usr/local/nginx-1.7.0/sbin/nginx -s stop

重置:當你有修改配置文件的時候,只需要reload以下即可

復制代碼代碼如下:
/usr/local/nginx-1.7.0/sbin/nginx -s reload

整個nginx的安裝就到這里結束了。

四、nginx編譯參數詳解

復制代碼代碼如下:

–prefix= 指向安裝目錄
–sbin-path 指向(執行)程序文件(nginx)
–conf-path= 指向配置文件(nginx.conf)
–error-log-path= 指向錯誤日誌目錄
–pid-path= 指向pid文件(nginx.pid)
–lock-path= 指向lock文件(nginx.lock)(安裝文件鎖定,防止安裝文件被別人利用,或自己誤操作。)
–user= 指定程序運行時的非特權用戶
–group= 指定程序運行時的非特權用戶組
–builddir= 指向編譯目錄
–with-rtsig_mole 啟用rtsig模塊支持(實時信號)
–with-select_mole 啟用select模塊支持(一種輪詢模式,不推薦在高載環境下使用)禁用:–without-select_mole
–with-poll_mole 啟用poll模塊支持(功能與select相同,與select特性相同,為一種輪詢模式,不推薦在高載環境下使用)
–with-file-aio 啟用file aio支持(一種APL文件傳輸格式)
–with-ipv6 啟用ipv6支持
–with-http_ssl_mole 啟用ngx_http_ssl_mole支持(使支持https請求,需已安裝openssl)
–with-http_realip_mole 啟用ngx_http_realip_mole支持(這個模塊允許從請求標頭更改客戶端的IP地址值,默認為關)
–with-http_addition_mole 啟用ngx_http_addition_mole支持(作為一個輸出過濾器,支持不完全緩沖,分部分響應請求)
–with-http_xslt_mole 啟用ngx_http_xslt_mole支持(過濾轉換XML請求)
–with-http_image_filter_mole 啟用ngx_http_image_filter_mole支持(傳輸JPEG/GIF/PNG 圖片的一個過濾器)(默認為不啟用。gd庫要用到)
–with-http_geoip_mole 啟用ngx_http_geoip_mole支持(該模塊創建基於與MaxMind GeoIP二進制文件相配的客戶端IP地址的ngx_http_geoip_mole變數)
–with-http_sub_mole 啟用ngx_http_sub_mole支持(允許用一些其他文本替換nginx響應中的一些文本)
–with-http_dav_mole 啟用ngx_http_dav_mole支持(增加PUT,DELETE,MKCOL:創建集合,COPY和MOVE方法)默認情況下為關閉,需編譯開啟
–with-http_flv_mole 啟用ngx_http_flv_mole支持(提供尋求內存使用基於時間的偏移量文件)
–with-http_gzip_static_mole 啟用ngx_http_gzip_static_mole支持(在線實時壓縮輸出數據流)
–with-http_random_index_mole 啟用ngx_http_random_index_mole支持(從目錄中隨機挑選一個目錄索引)
–with-http_secure_link_mole 啟用ngx_http_secure_link_mole支持(計算和檢查要求所需的安全鏈接網址)
–with-http_degradation_mole 啟用ngx_http_degradation_mole支持(允許在內存不足的情況下返回204或444碼)
–with-http_stub_status_mole 啟用ngx_http_stub_status_mole支持(獲取nginx自上次啟動以來的工作狀態)
–without-http_charset_mole 禁用ngx_http_charset_mole支持(重新編碼web頁面,但只能是一個方向–伺服器端到客戶端,並且只有一個位元組的編碼可以被重新編碼)
–without-http_gzip_mole 禁用ngx_http_gzip_mole支持(該模塊同-with-http_gzip_static_mole功能一樣)
–without-http_ssi_mole 禁用ngx_http_ssi_mole支持(該模塊提供了一個在輸入端處理處理伺服器包含文件(SSI)的過濾器,目前支持SSI命令的列表是不完整的)
–without-http_userid_mole 禁用ngx_http_userid_mole支持(該模塊用來處理用來確定客戶端後續請求的cookies)
–without-http_access_mole 禁用ngx_http_access_mole支持(該模塊提供了一個簡單的基於主機的訪問控制。允許/拒絕基於ip地址)
–without-http_auth_basic_mole禁用ngx_http_auth_basic_mole(該模塊是可以使用用戶名和密碼基於http基本認證方法來保護你的站點或其部分內容)
–without-http_autoindex_mole 禁用disable ngx_http_autoindex_mole支持(該模塊用於自動生成目錄列表,只在ngx_http_index_mole模塊未找到索引文件時發出請求。)
–without-http_geo_mole 禁用ngx_http_geo_mole支持(創建一些變數,其值依賴於客戶端的IP地址)
–without-http_map_mole 禁用ngx_http_map_mole支持(使用任意的鍵/值對設置配置變數)
–without-http_split_clients_mole 禁用ngx_http_split_clients_mole支持(該模塊用來基於某些條件劃分用戶。條件如:ip地址、報頭、cookies等等)
–without-http_referer_mole 禁用disable ngx_http_referer_mole支持(該模塊用來過濾請求,拒絕報頭中Referer值不正確的請求)
–without-http_rewrite_mole 禁用ngx_http_rewrite_mole支持(該模塊允許使用正則表達式改變URI,並且根據變數來轉向以及選擇配置。如果在server級別設置該選項,那麼他們將在 location之前生效。如果在location還有更進一步的重寫規則,location部分的規則依然會被執行。如果這個URI重寫是因為location部分的規則造成的,那麼 location部分會再次被執行作為新的URI。 這個循環會執行10次,然後Nginx會返回一個500錯誤。)
–without-http_proxy_mole 禁用ngx_http_proxy_mole支持(有關代理伺服器
–without-http_fastcgi_mole 禁用ngx_http_fastcgi_mole支持(該模塊允許Nginx 與FastCGI 進程交互,並通過傳遞參數來控制FastCGI 進程工作。 )FastCGI一個常駐型的公共網關介面。
–without-http_uwsgi_mole 禁用ngx_http_uwsgi_mole支持(該模塊用來醫用uwsgi協議,uWSGI伺服器相關)
–without-http_scgi_mole 禁用ngx_http_scgi_mole支持(該模塊用來啟用SCGI協議支持,SCGI協議是CGI協議的替代。它是一種應用程序與HTTP服務介面標准。它有些像FastCGI但他的設計 更容易實現。)
–without-http_memcached_mole 禁用ngx_http_memcached_mole支持(該模塊用來提供簡單的緩存,以提高系統效率)
-without-http_limit_zone_mole 禁用ngx_http_limit_zone_mole支持(該模塊可以針對條件,進行會話的並發連接數控制)
–without-http_limit_req_mole 禁用ngx_http_limit_req_mole支持(該模塊允許你對於一個地址進行請求數量的限制用一個給定的session或一個特定的事件)
–without-http_empty_gif_mole 禁用ngx_http_empty_gif_mole支持(該模塊在內存中常駐了一個1*1的透明GIF圖像,可以被非常快速的調用)
–without-http_browser_mole 禁用ngx_http_browser_mole支持(該模塊用來創建依賴於請求報頭的值。如果瀏覽器為modern ,則$modern_browser等於modern_browser_value指令分配的值;如 果瀏覽器為old,則$ancient_browser等於 ancient_browser_value指令分配的值;如果瀏覽器為 MSIE中的任意版本,則 $msie等於1)
–without-http_upstream_ip_hash_mole 禁用ngx_http_upstream_ip_hash_mole支持(該模塊用於簡單的負載均衡)
–with-http_perl_mole 啟用ngx_http_perl_mole支持(該模塊使nginx可以直接使用perl或通過ssi調用perl)
–with-perl_moles_path= 設定perl模塊路徑
–with-perl= 設定perl庫文件路徑
–http-log-path= 設定access log路徑
–http-client-body-temp-path= 設定http客戶端請求臨時文件路徑
–http-proxy-temp-path= 設定http代理臨時文件路徑
–http-fastcgi-temp-path= 設定http fastcgi臨時文件路徑
–http-uwsgi-temp-path= 設定http uwsgi臨時文件路徑
–http-scgi-temp-path= 設定http scgi臨時文件路徑
-without-http 禁用http server功能
–without-http-cache 禁用http cache功能
–with-mail 啟用POP3/IMAP4/SMTP代理模塊支持
–with-mail_ssl_mole 啟用ngx_mail_ssl_mole支持
–without-mail_pop3_mole 禁用pop3協議(POP3即郵局協議的第3個版本,它是規定個人計算機如何連接到互聯網上的郵件伺服器進行收發郵件的協議。是網際網路電子郵件的第一個離線協議標 准,POP3協議允許用戶從伺服器上把郵件存儲到本地主機上,同時根據客戶端的操作刪除或保存在郵件伺服器上的郵件。POP3協議是TCP/IP協議族中的一員,主要用於 支持使用客戶端遠程管理在伺服器上的電子郵件)
–without-mail_imap_mole 禁用imap協議(一種郵件獲取協議。它的主要作用是郵件客戶端可以通過這種協議從郵件伺服器上獲取郵件的信息,下載郵件等。IMAP協議運行在TCP/IP協議之上, 使用的埠是143。它與POP3協議的主要區別是用戶可以不用把所有的郵件全部下載,可以通過客戶端直接對伺服器上的郵件進行操作。)
–without-mail_smtp_mole 禁用smtp協議(SMTP即簡單郵件傳輸協議,它是一組用於由源地址到目的地址傳送郵件的規則,由它來控制信件的中轉方式。SMTP協議屬於TCP/IP協議族,它幫助每台計算機在發送或中轉信件時找到下一個目的地。)
–with-google_perftools_mole 啟用ngx_google_perftools_mole支持(調試用,剖析程序性能瓶頸)
–with-cpp_test_mole 啟用ngx_cpp_test_mole支持
–add-mole= 啟用外部模塊支持
–with-cc= 指向C編譯器路徑
–with-cpp= 指向C預處理路徑
–with-cc-opt= 設置C編譯器參數(PCRE庫,需要指定–with-cc-opt=」-I /usr/local/include」,如果使用select()函數則需要同時增加文件描述符數量,可以通過–with-cc- opt=」-D FD_SETSIZE=2048」指定。)
–with-ld-opt= 設置連接文件參數。(PCRE庫,需要指定–with-ld-opt=」-L /usr/local/lib」。)
–with-cpu-opt= 指定編譯的CPU,可用的值為: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64
–without-pcre 禁用pcre庫
–with-pcre 啟用pcre庫
–with-pcre= 指向pcre庫文件目錄
–with-pcre-opt= 在編譯時為pcre庫設置附加參數
–with-md5= 指向md5庫文件目錄(消息摘要演算法第五版,用以提供消息的完整性保護)
–with-md5-opt= 在編譯時為md5庫設置附加參數
–with-md5-asm 使用md5匯編源
–with-sha1= 指向sha1庫目錄(數字簽名演算法,主要用於數字簽名)
–with-sha1-opt= 在編譯時為sha1庫設置附加參數
–with-sha1-asm 使用sha1匯編源
–with-zlib= 指向zlib庫目錄
–with-zlib-opt= 在編譯時為zlib設置附加參數
–with-zlib-asm= 為指定的CPU使用zlib匯編源進行優化,CPU類型為pentium, pentiumpro
–with-libatomic 為原子內存的更新操作的實現提供一個架構
–with-libatomic= 指向libatomic_ops安裝目錄
–with-openssl= 指向openssl安裝目錄
–with-openssl-opt 在編譯時為openssl設置附加參數
–with-debug 啟用debug日誌

J. 如何在linux上安裝nginx

#forcentos
yuminstall-yepel-release&&yumcleanall&&yummakecache
yuminstall-ynginx

如果編譯安裝的話需要很多依賴包。YUM安裝是最簡單的。

熱點內容
mill91編程 發布:2025-02-06 13:10:27 瀏覽:291
華為平板怎麼儲存伺服器文件 發布:2025-02-06 12:49:21 瀏覽:481
php查詢結果數組 發布:2025-02-06 12:31:05 瀏覽:716
怎樣把照片壓縮打包 發布:2025-02-06 12:15:19 瀏覽:498
如何編譯java文件 發布:2025-02-06 12:05:58 瀏覽:237
九九乘法編程 發布:2025-02-06 12:05:05 瀏覽:519
台式機忘記開機密碼怎麼辦 發布:2025-02-06 11:58:01 瀏覽:871
android刷新按鈕 發布:2025-02-06 11:57:17 瀏覽:586
存儲過程有輸入參數和輸出參數 發布:2025-02-06 11:55:32 瀏覽:99
成績評選演算法 發布:2025-02-06 11:42:51 瀏覽:997