當前位置:首頁 » 操作系統 » linux下配置nginx

linux下配置nginx

發布時間: 2024-07-01 01:48:34

⑴ 怎麼在linux上搭建nginx

(0) 安裝依賴包
yum -y install pcre*
yum install autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
yum -y install pcre-devel
yum -y install openssl openssl-devel
yum -y install lrzsz
yum -y install gcc gcc-c++
yum -y install openssl*


(1) 編譯安裝 PCRE
wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gz
tar zxvf pcre-7.7.tar.gz
cd pcre-7.7
./configure
make
make install
下載 pcre-8.31.tar.gz
[root@localhost /]# cd /media/psf/Home/Downloads
[root@localhost Downloads]# mv pcre-8.31.tar.gz /home/Nginx
[root@localhost Downloads]# cd /home/Nginx
[root@localhost Nginx]# tar -zxvf pcre-8.31.tar.gz
[root@localhost Nginx]# cd pcre-8.31
[root@localhost pcre-8.31]#
[root@localhost pcre-8.31]# make
[root@localhost pcre-8.31]# make install


(2) 編譯安裝 nginx-sticky-mole-1.1
[root@localhost Downloads]# cd /home/Nginx
[root@localhost Nginx]# mkdir nginx-sticky-mole-1.1
[root@localhost Nginx]# cd /media/psf/Home/Downloads
[root@localhost Downloads]#
mv nginx-sticky-mole-1.1.tar.gz /home/Nginx/nginx-sticky-mole-1.1/
[root@localhost Downloads]# cd /home/Nginx/nginx-sticky-mole-1.1/
[root@localhost nginx-sticky-mole-1.1]# tar -zxvf nginx-sticky-mole-1.1.tar.gz

(3) 下載 nginx
[root@localhost local]# wget http://nginx.org/download/nginx-1.7.8.tar.gz

(4) 新建一個 Nginx 目錄
[root@localhost /]# cd home
[root@localhost home]# mkdir Nginx

(5) 將 tar 包移動到 /home/Nginx 目錄下面
[root@localhost local]# mv nginx-1.7.8.tar.gz /home/Nginx
[root@localhost local]# cd /home/Nginx

(6) 將 tar 包解壓
[root@localhost Nginx]# tar -zxvf nginx-1.7.8.tar.gz
[root@localhost Nginx]# cd nginx-1.7.8
[root@localhost nginx-1.7.8]#
./configure --prefix=/usr/local/nginx-1.7.8 --with-http_ssl_mole --with-http_spdy_mole --with-http_stub_status_mole --with-pcre
make && make install


(7) 驗證安裝是否成功
[root@localhost /]# cd /usr/local/nginx-1.7.8/sbin
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

(8) 啟動 nginx
[root@localhost sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
使用命令關閉佔用80埠的程序 sudo fuser -k 80/tcp

[root@localhost sbin]# ./nginx


(9) 瀏覽器訪問:成功

至此,Nginx 安裝完畢;

⑵ 怎麼在linux下搭建一個nginx伺服器

大家對Nginx伺服器有了解嗎?如果想要了解網站伺服器的朋友,那麼就需要學習一下在電腦中搭建Nginx WEB伺服器的基礎,Nginx主要是用在Linux的主機上,不過它也可以運行在Windows上,下面就讓小編為大家介紹下,如何在Winxp系統中搭建Nginx WEB伺服器。 Winxp系統的電腦怎麼搭建Nginx WEB伺服器 具體方法如下: 1、下載Nginx程序包,僅有1M左右大小,相當小巧功能強大! 2、將下載好的zip壓縮包的文件全部解壓,雙擊運行nginx.exe,你會看到一個黑色窗口一閃而過就沒了,這就說明Nginx伺服器已經正式啟動(沒有程序界面的)。 3、在瀏覽器輸入訪問 127.0.0.1 回車,如果看到「Welcome to nginx!」則說明你在本機搭建的伺服器已經成功運行。如果沒有,請檢查你的電腦的80埠是否被佔用,或者打開任務管理器查看一下是否有兩個「nginx.exe」進程在運行。 4、完成以上簡單的三步後,我們的Nginx網頁伺服器就搭建完成了,但是呢到這里只能支持html的純網頁,如果想讓它支持php腳本還需要進一步安裝php的運行環境。 以上方法操作起來十分便捷,想要在XP系統上免費搭建Nginx伺服器的小夥伴們快來看看吧。如有更多疑問,歡迎訪問安下軟體站。

⑶ linux nginx配置

./nginx -s quit:此方式停止步驟是待nginx進程處理任務完畢進行停止。
./nginx -s stop:此方式相當於先查出nginx進程id再使用kill命令強制殺掉進程。

重啟 nginx
1.先停止再啟動(推薦):
對 nginx 進行重啟相當於先停止再啟動,即先執行停止命令再執行啟動命令。如下:

2.重新載入配置文件:

當 ngin x的配置文件 nginx.conf 修改後,要想讓配置生效需要重啟 nginx,使用-s reload不用先停止 ngin x再啟動 nginx 即可將配置信息在 nginx 中生效,如下:

啟動成功後,在瀏覽器可以看到這樣的頁面:
Welcome to nginx!
....

⑷ 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

⑸ 虛擬機linux配置nginx 為什麼win7通過Ip訪問不到

第一步,你應該先檢查網路,
win機ping linux機,通了進行下一步。
第二步,檢查埠,
netstat -antl | grep 你開啟的服務埠,
比如你開了http,那就是80埠或者你自定義的埠,我就不多說了。
第三步,檢查防火牆,
service iptables stop,
可以直接先關掉防火牆看是不是能訪問了,如果可以,說明是防火牆屏蔽掉了,可以設備防火牆放行對應埠。

⑹ linux 版怎麼配置nginx

配置Nginx服務

Nginx是一款相當優秀的用於部署動態網站的服務程序,Nginx最初是為俄羅斯門戶站點而設計的網站服務軟體,作為一款輕量級的網站服務軟體,因其穩定性和豐富的功能而深受信賴,但最最最被認可的是低系統資源、佔用內存少且並發能力強,目前國內如新浪、網易、騰訊等門戶站均在使用,市場佔有份額一直保持在15-16%左右(2015年最新數據)。

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服務是否順利運行

LNMP(即Linux+Nginx+MYSQL+PHP)是目前非常熱門的動態網站部署架構,如果你是在搭建這種部署的話可以看下http://www.linuxprobe.com/chapter-20.html

熱點內容
java輸出快捷鍵 發布:2024-07-02 23:37:56 瀏覽:743
androidxml字元轉義 發布:2024-07-02 23:32:33 瀏覽:491
elflinux 發布:2024-07-02 23:31:53 瀏覽:553
sql語句過長 發布:2024-07-02 23:24:34 瀏覽:983
account文件夾 發布:2024-07-02 23:07:03 瀏覽:930
打開網頁停止腳本 發布:2024-07-02 22:55:28 瀏覽:697
賓館電腦無法連接到伺服器 發布:2024-07-02 22:51:15 瀏覽:710
ipad忘記id密碼怎麼辦啊 發布:2024-07-02 22:43:37 瀏覽:439
新版uc不能緩存小說 發布:2024-07-02 22:09:55 瀏覽:914
linux線程函數 發布:2024-07-02 21:56:36 瀏覽:163