① 如何編譯安裝nginx1.8.1
因素很多, 可能是版本不正確, 可能是系統環境沒有安裝好啊 ,。看看wo 的網名一下吧,一定能解決問題的啊 1
② 怎麼在centos 6.5安裝nginx
一、准備事項
(1) 因為nginx需要訪問80埠所以請先關閉或者開放防火牆埠,和selinux。
參考命令
關閉防火牆:
[root@local ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@local ~]# service iptables save
關閉selinux:
[root@local ~]# setenforce 0
[root@local ~]# vim /etc/selinux/config
將SELINUX=enforcing改為SELINUX=disabled
(2) 如果用到域名請自行構建DNS服務
二、安裝
(1) 因為nginx的運行需要安裝pcre、zlib等軟體包,因此我們進行安裝
Pcre=Pcre Compatible Regular Expressions(中文pcre兼容正則表達式)
Yum配置請參考: http://www.linuxidc.com/Linux/2015-11/125332.htm
[root@local ~] yum -y install pcre* zlib* #或者進行編譯安裝
[root@local ~]# useradd -M -s /sbin/nologin nginx #創建nginx服務
啟動用戶
(3) 編譯安裝nginx,下載地址:http://nginx.org/en/download.html 此次安裝為最新穩定版nginx-1.8.0
[root@local ~]# tar zxf nginx-1.8.0.tar.gz
[root@local ~]# cd nginx-1.8.0
[root@local nginx-1.8.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[root@local nginx-1.8.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.8.0 --with-http_stub_status_mole --with-http_ssl_mole #./configure –help 參數詳解
[root@local nginx-1.8.0]# make
[root@local nginx-1.8.0]# make install
(4) 製作軟連接
[root@local nginx-1.8.0]#ln –a /application/nginx-1.8.0/
/application/nginx
(5) 基本使用
#語法檢查
[root@local nginx-1.8.0]# /application/nginx/sbin/nginx –t
nginx: the configuration file /application/nginx-1.8.0/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.8.0/conf/nginx.conf test is successful
#啟動服務
[root@local nginx-1.8.0]# /application/nginx/sbin/nginx
#埠檢查
[root@local nginx-1.8.0]# netstat –lnt
#檢查進程
[root@local nginx-1.8.0]# ps -ef | grep nginx #埠信息保存在
/application/nginx/logs/ nginx.pid 文件中
#通過埠查看佔用進程
[root@local nginx-1.8.0]# lsof -i :80
#錯誤日誌
/application/nginx/logs/error.log
三、編寫nginx服務腳本
為了方便使用習慣,通過server 來啟動、關閉、開啟、重載nginx服務所以我們來編
寫nginx的服務腳本(自己編寫的腳本僅供參考!)
[root@local ~]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: - 99 20
#description:Nginx Server Contorl Script
PROG="/application/nginx/sbin/nginx"
PIDF="/application/nginx/logs/nginx.pid"
ok=`echo -e "\e[1;31m [ok] \e[0m"`
no=`echo -e "\e[1;31m [no] \e[0m"`
detection=`/application/nginx/sbin/nginx -t 2>&1`
screen_1=`echo $detection | awk '{print $6,$7,$8}'`
screen_2=`echo $detection | awk '{print $13,$14,$15}'`
if [ "$screen_1" = "syntax is ok" ] && [ "$screen_2" = "test is successful" ];
then
case "$1" in
start)
$PROG
echo "Nginx Is starting state $ok"
;;
stop)
kill -s QUIT $(cat $PIDF)
echo "Nginx Is closing state $ok"
;;
restart)
$0 stop
$0 start
echo "Nginx Is to restart state $ok"
;;
reload)
kill -s HUP $(cat $PIDF)
echo "Nginx Is overloaded state $ok"
;;
*)
echo "Usage: $0 (start|stop|restart|reload)"
exit 1
esac
else
echo "Nginx check state $no "
echo "Please check the configuration file"
echo "$detection"
fi
exit 0
[root@local ~]# chmod +x /etc/init.d/nginx
[root@local ~]# chkconfig –add nginx #添加為系統服務
[root@local ~]# chkconfig nginx on
四、簡單的nginx web站點
Nginx的默認站點目錄,是安裝目錄下的html這里是(/application/nginx/html)
在主配置文件/application/nginx/conf/nginx.conf 中查看,對於重新部署web頁面
只需將/application/nginx/html/中的index.html替換即可
主配置文件講解
[root@local ~]# egrep -v "#|^$" /application/nginx/conf/nginx.conf
worker_processes 1; #指定Nginx開啟的進程數
events { #設定Nginx的工作模式及連接數上線
worker_connections 1024;
}
http {
include mime.types; #主模塊命令,實現對配置文件所有包含文件的設置
default_type application/octet-stream; #屬於http核心模塊命令,這里設
置類型為二進制流,也就是當文件類型未定義時使用這種方式,例如,沒有配置php
環境時,nginx是不給予解析的,此時,用瀏覽器訪問PHP文件就會出現下載窗口。
sendfile on; #用於高效文件傳輸模式
keepalive_timeout 65; 設置客戶端請求頭文件讀取超時時間,如果超過這個時
間伺服器會關閉該連接。
server { #定義虛擬主機開始的關鍵字
listen 80; #用於指定虛擬主機的服務埠
server_name localhost; 用於指定ip地址或者域名,多個域名用空格隔開
location / {
root html;
index index.html index.htm; #用於設定訪問的默認首頁
}
error_page 500 502 503 504 /50x.html;# 靜態頁面重定向伺服器錯誤
頁面,例如攜程的網站崩潰出現的頁面
location = /50x.html {
root html;
}
}
}
③ 如何安裝nginx
方法/步驟
安裝nginx前,我們首先要確保系統安裝了g++、gcc、openssl-devel、pcre-devel和zlib-devel軟體,可通過如圖所示命令進行檢測,如果以安裝我們可以通過圖二所示卸載
我們一般安裝linux軟體都會在/usr/local目錄下,然後進行解壓編譯安裝,具體的命令大家請看圖片所示
等待配置和編譯完成,完成後我們就需要配置防火牆,不攔截80埠,設置完成後需要重啟防火牆
接下來介紹下啟動/停止/重啟的具體方法,進入目錄後我們可以用執行sbin/nginx來啟動,也可以通過conf/nginx.conf來啟動,停止我們可以查詢進程使用kill -9 進程號/pkill -9 nginx來結束nginx服務,重啟可以通過 sbin/nginx -s reload來重啟,具體命令大家請看如圖所示
下面來說說基本的操作命令,
nginx -h #幫助
nginx -v #顯示版本
nginx -V #顯示版本和配置信息
nginx -t #測試配置
nginx -q #測試配置時,只輸出錯誤信息
nginx -s stop #停止伺服器
nginx -s reload #重新載入配置
然後請看圖片所示conf文件的配置,來配置nginx的方法
④ 如何在linux下編譯nginx
安裝nginx
1.下載
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了。
⑤ centos7怎麼編譯安裝nginx1.95+mariadb10.1+php7
如果你nginx是rpm包安裝的,直接用如下命令:
nginx -V 如果你是源碼包編譯安裝
如果你的安裝路徑是/usr/local/nginx,那麼你可以使用:
/usr/local/nginx/sbin/nginx -V 注意是大寫的V,
這樣你就可以看到nginx已經載入的模塊了。
⑥ 如何源碼編譯安裝nginx
安裝前提
在安裝nginx前,需要確保系統安裝了g++、gcc
1.安裝openssl軟體
#
#進入安裝目錄
cd /usr/local/
#刪除原有安裝
rm -rf openssl
rm -rf openssl-1.0.2d
#解壓
tar -zxv -f openssl-1.0.2d.tar.gz
#進入源碼目錄
cd openssl-1.0.2d
#配置
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl/conf
#編譯安裝
make && make install
#檢驗安裝
/usr/local/openssl/bin/openssl version -a
2.安裝pcre軟體
#進入安裝目錄
cd /usr/local/
#刪除原有安裝
rm -rf pcre
rm -rf pcre-8.37
#解壓
tar -zxv -f pcre-8.37.tar.gz
#進入源碼目錄
cd pcre-8.37
#執行配置
./configure --prefix=/usr/local/pcre/
#編譯安裝
make && make install
3.安裝zlib軟體
#進入安裝目錄
cd /usr/local/
#刪除原有安裝
rm -rf zlib
rm -rf zlib-1.2.8
#解壓
tar -zxv -f zlib-1.2.8.tar.gz
#進入源碼目錄
cd zlib-1.2.8
#配置
./configure --prefix=/usr/local/zlib/
# 編譯安裝
make && make install
4. 安裝nginx軟體
#----------------------------------------------------------------
# 安裝前提: openssl、pcre、zlib
# 注意:
# 不使用自已安裝的openssl的時候,要安裝openssl-devel,否則編譯不通過。
# yum install openssl-devel 此時參數可以不使用--with-open_ssl=/usr/local/openssl-1.0.1g
#----------------------------------------------------------------
#添加www用戶和組
groupadd www
useradd -g www www
#創建網站根目錄
mkdir -p /var/www/root/
chmod -R 775 /var/www/root/
#進入安裝目錄
cd /usr/local
#刪除原有安裝
rm -rf nginx
rm -rf nginx-1.8.0
#解壓
tar -zxvf nginx-1.8.0.tar.gz
#進入安裝目錄
cd nginx-1.8.0
#配置(使用openssl、pcre、zlib的源碼路徑)
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_ssl_mole \
--with-openssl=/usr/local/openssl-1.0.2d \
--with-pcre=/usr/local/pcre-8.37 \
--with-zlib=/usr/local/zlib-1.2.8 \
--with-http_stub_status_mole \
--with-threads
#編譯安裝
make && make install
#驗證
/usr/local/nginx/sbin/nginx -V
⑦ lnmp安裝中怎麼配置nginx
LNMP一鍵安裝包安裝好後,相應的Mysql,Nginx及PHP都會安裝配置完成。
由於某些特殊情況的需要,如何更換Nginx的版本呢?
nginx升級腳本可以完成。
1、 手動編譯方法:/usr/local/nginx刪了再重新進入./lnmp0.8-full/nginx/1.0.10進行make install也可以達到重裝效果
注意保存Nginx的配置文件
可以再重新make install
刪除nginx目錄前備份配置文件
make install後需要重新復制備份文件
2、發布的腳本就是專門用來升級Nginx,可以升級Nginx至任意官方已發布的Nginx版本。
執行:wget soft.vpser.net/lnmp/upgrade_nginx.sh;sh upgrade_nginx.sh
然後按提示輸入要升級的Nginx版本號,Nginx的版本號可以從http://nginx.org/en/download.html查詢。輸入版本號後回車,再次回車確認即可開始安裝,如果不出意外就會升級成功,如果出現問題可以到http://bbs.vpser.net lnmp專區發帖求助。
⑧ 如何在 centos 7 中編譯安裝 nginx1.7.8
1.先從nginx官網下載最新的版本 http://nginx.org/download/nginx-1.7.8.tar.gz
2.解壓nginx-1.7.8.tar.gz,然後執行下面操作即可
./configure --prefix=/usr/local/nginx
make
make install
⑨ 如何安裝nginx
一、下載→編譯→安裝→啟動
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文檔中找到。