優班圖安裝nginx編譯環境
㈠ ubuntu 16.04下怎樣安裝nginx
2種方法:
1,apt-get install nginx
2,網上下載nginx安裝包,然後編譯
㈡ 如何在ubuntu下 安裝nginx伺服器
獲取nginx源碼
1、打開網路在搜索欄輸入nginx找到nginx官網,點擊進入;
2、點擊最新發布版,進入下載地址;
3、找到最新源碼,右擊獲取源碼下載地址通過wget下載;
如何在ubuntu下 安裝nginx伺服器
如何在ubuntu下 安裝nginx伺服器
如何在ubuntu下 安裝nginx伺服器
如何在ubuntu下 安裝nginx伺服器
配置編譯安裝
配置
./configure --prefix=/usr/local/nginx
編譯、安裝
make && make install
配置過程可能出現:
錯誤描述:error: the HTTP rewrite mole requires the PCRE library
解決方法:
需要安裝pcre包。
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
你可能還需要安裝
sudo apt-get install openssl libssl-dev
如何在ubuntu下 安裝nginx伺服器
如何在ubuntu下 安裝nginx伺服器
3
啟動nginx
進入nginx安裝目錄,找到nginx目錄所在目錄,執行./nginx -c /usr/local/nginx/conf/nginx.conf啟動服務;
在瀏覽器輸入web伺服器地址http://127.0.0.1,瀏覽器顯示速度超級快,顯示如圖說明nginx安裝啟動成功
如何在ubuntu下 安裝nginx伺服器
㈢ 怎麼編譯安裝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
㈣ ubuntu怎麼編譯nginx
先解壓nginx的tar包,進入解壓後的文件夾里,如果要安裝到其他路徑的話,修改configure文件里的prefix的值然後執行./configure,或者直接使用./configure --prefix=/xx/xx/xxx來指定,安裝路徑然後make -j2,如果你的處理器核多,可以增大數字,再然後就是make & make install了。
要注意的是./configure後面可以跟隨很多參數配置:
比如,需要的話可以加上--config-path=/xx/xx/xxx/nginx.conf指定nginx的伺服器配置文件路徑;
--add-mole增加模塊,比如luz、pagespeed、upstream等等,這些都可以在官網上查到。
㈤ 如何安裝nginx
部署安裝nignx的環境
yum-yinstallgccgcc-c++ncurses-devellibxml2-devel
openssl-develcurl-devellibjpeg-devellibpng-develautoconfpcre-devel
libtool-libsfreetype-develgdzlib-develzipunzip
-devel
glibc-develglibc-staticglib2-develbzip2-devel
gettext-devellibcap-devellogrotatentp
libmcrypt-develpatch
2.下載安裝nginx
wgethttp://nginx.org/download/nginx-1.10.2.tar.gz--獲取nignx安裝包
tar-zxvf./nginx-1.10.2.tar.gz--解壓安裝包
cd./nginx-1.10.2
./configure
--with-stream---開啟tcp代理
--with-http_ssl_mole---開啟https
make---編譯nginx
makeinstall--安裝nginx
3.啟動nginx
nginx啟動命令(注意nginx默認使用80埠,如果80埠已經使用,請去nginx.conf修改默認埠)
/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
4.yum安裝nginx。
yum-yinstallnginx
servicenginxstart--啟動nginx
servicenginxstop--停止nginx
servicenginxrestart--重啟nginx
5.編譯安裝的nginx配置文件在/usr/local/nginx/conf/nginx.conf,網站在/usr/local/nginx/html/下面。yum安裝的nginx配置文件在/etc/nginx/nginx.conf,網站在/var/www/html/下面
㈥ 在Ubuntu 里有沒有什麼命令確定 Nginx 配置文件位置
當你執行 nginx -t
得時候,nginx會去測試你得配置文件得語法,並告訴你配置文件是否寫得正確,同時也告訴了你配置文件得路徑:
# nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
㈦ 源碼安裝nginx需要安裝哪些東西
nginx配置裡面配置一個server段,然後把網站的目錄,域名,別名等配置好就可以了。想要好管理配置,用include加個文單花廁拘丿餃搽邪敞矛件,裡面專門配置server段
㈧ 如何編譯安裝nginx1.8.1
因素很多, 可能是版本不正確, 可能是系統環境沒有安裝好啊 ,。看看wo 的網名一下吧,一定能解決問題的啊 1
㈨ ubuntu怎麼安裝nginx
Nginx程序的穩定性來自於它採用了分階段的資源分配技術,使得CPU與內存佔用率會非常低,所以使用Nginx程序部署動態網站環境不僅十分的穩定、高效,而且消耗更少的系統資源,豐富的模塊功能也幾乎與Apache程序數量相同,現在已經完全的支持了proxy、rewrite、mod_fcgi、ssl、vhosts等常用模塊。而且還支持了熱部署技術,即能夠可以7*24不間斷提供服務,即便運行數月也無須重啟,而且還可以在不暫停服務的情況下直接對Nginx服務程序進行升級。
坦白來講,雖然Nginx程序的代碼質量非常高,代碼很規范,技術成熟,模塊擴展也很容易,但Nginx依然存在不少問題,比如Nginx是由俄羅斯人創建的,所以在資料文檔方面還並不完善,中文教材的質量更是魚龍混雜,但Nginx近年來增長勢頭迅猛,預測未來應該能夠在輕量級HTTP伺服器市場有不錯的未來。
安裝PCRE(Perl兼容的正則表達式庫,解壓與編譯過程已省略):
[root@linuxprobe ~]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/pcre
[root@linuxprobe src]# tar xzvf pcre-8.35.tar.gz
[root@linuxprobe src]# cd pcre-8.35
[root@linuxprobe pcre-8.35]# ./configure --prefix=/usr/local/pcre
[root@linuxprobe pcre-8.35]# make
[root@linuxprobe pcre-8.35]# make install
安裝openssl服務程序(解壓與編譯過程已省略):
[root@linuxprobe pcre-8.35]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/openssl
[root@linuxprobe src]# tar xzvf openssl-1.0.1h.tar.gz
[root@linuxprobe src]# cd openssl-1.0.1h
[root@linuxprobe openssl-1.0.1h]# ./config --prefix=/usr/local/openssl
[root@linuxprobe openssl-1.0.1h]# make
[root@linuxprobe openssl-1.0.1h]# make install
把openssl服務程序命令目錄添加到環境變數中(永久生效):
[root@linuxprobe pcre-8.35]# vim /etc/profile
//將配置文件最下面的參數追加參數為:
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin
[root@linuxprobe pcre-8.35]# source /etc/profile
安裝zlib數據壓縮函數庫(解壓與編譯過程已省略):
[root@linuxprobe pcre-8.35]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/zlib
[root@linuxprobe src]# tar xzvf zlib-1.2.8.tar.gz
[root@linuxprobe src]# cd zlib-1.2.8
[root@linuxprobe zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@linuxprobe zlib-1.2.8]# make
[root@linuxprobe zlib-1.2.8]# make install
創建用於執行nginx服務的用戶:
[root@linuxprobe zlib-1.2.8]# cd ..
[root@linuxprobe src]# useradd www -s /sbin/nologin
安裝nginx服務程序(openssl,zlib,pcre要寫成源碼解壓路徑!!!):
[root@linuxprobe src]# tar xzvf nginx-1.6.0.tar.gz
[root@linuxprobe src]# cd nginx-1.6.0/
[root@linuxprobe nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --without-http_memcached_mole --user=www --group=www --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35
[root@linuxprobe nginx-1.6.0]# make
[root@linuxprobe nginx-1.6.0]# make install
創建nginx程序腳本(將下面的參數直接復制進去即可):
[root@linuxprobe nginx-1.6.0]# vim /etc/rc.d/init.d/nginx
#!/bin/bash
# nginx - this script starts and stops the nginx daemon
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
#configtest || return $?
stop
sleep 1
start
}
reload() {
#configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
[root@linuxprobe nginx-1.6.0]# chmod 755 /etc/rc.d/init.d/nginx
重啟nginx服務程序並添加到開機啟動項:
[root@linuxprobe nginx-1.6.0]# /etc/rc.d/init.d/nginx restart
Restarting nginx (via systemctl): [ OK ]
[root@linuxprobe nginx-1.6.0]# chkconfig nginx on
此時可以通過訪問IP來判斷nginx服務是否順利運行
我們一般通過部署Linux+Nginx+MYSQL+PHP這四種開源軟體,搭建一個免費、高效、擴展性強、資源消耗低的LNMP動態網站架構。關於這塊的安裝使用你可以看下http://www.linuxprobe.com/chapter-20.html#2022_Nginx
㈩ linux ubuntu13.10安裝nginx1.8.0需要哪些編譯環境
sudo//換到rootconfigure //對安裝的軟體進行配置--prefix=/usr/local/server/nginx //安裝目錄/usr/local/server/nginx--with-http_stub_status_mole啟用 nginx 的 NginxStatus 功能