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

編譯安裝nginx

發布時間: 2022-01-15 17:23:28

『壹』 沒有編譯環境怎麼安裝nginx

要編譯安裝Nginx,首先我們要安裝依賴...
1

准備工作完成後就是下載編譯安裝Nginx...
2

等編譯安裝完成後在 /usr/local 下就會...
3

由於腳本是我自己寫的,

『貳』 求大神指導Centos7 源碼編譯安裝Nginx+php 配置動靜分離

這個是我的服務的實際 將配置Nginx實現動靜分離,對php頁面的請求轉發給LAMP處理,而靜態頁面交給Nginx,以實現動靜分離。客戶請求靜態數據給Nginx,Nginx直接應答客戶端,當請求動態數據到Nginx時,Nginx讓客戶端去找LAMP,通過代理的方式,LAMP就和客戶端連接了。分別配置動態分離和靜態分離

(1)架設並調試後端LAMP架構,指定的域名,IP地址為xxxx,創建動態頁面test.php。

(2)配置Nginx(xxxx)處理動態頁面請求,並把域名改為 chaodiquan.com 在server{};段中加入以下代碼,檢測語法後,重啟Nginx

(3)客戶端輸入xxxx/test.php 成功後動態分離就實現了,接下來再配置靜態分離

(4)配置Nginx處理靜態頁面請求,在server{};中加入以下代碼,檢測語法後,重啟Nginx

location ~ .*.(gif|jpg|jpeg|bmp|swf)$ { #這段代碼意思是任意網址以這5種格式為結尾就到Nginx根目錄下的html文件夾尋找資源

root html;
expires 1d; #緩存一天}

(5)在nginx的html目錄中,放入圖片aa.jpg,然後在apache的動態測試頁test.php中添加

<html>
<body>
<img src="aaaa/aa.jpg">
</body>
</html>

(6)客戶端輸入xxxx/test.php測試,由於test.php是動態頁面,因此客戶端會找到LAMP架構中的Apache,然後調取圖片aa.jpg是靜態數據,所以從Nginx提取,最後反饋給客戶端。這個是

『叄』 如何在linux下編譯nginx

安裝nginx

1.下載

2.解壓

復制代碼代碼如下:

tar -zxvf nginx-1.7.0.tar.gz

3.編譯和安裝

執行如下命令:

#cdnginx-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了。

『肆』 編譯安裝nginx的配置文件的路徑在哪

這個版本不同,位置還是不同的。
我的是nginx-1.9.9版本源碼安裝,配置文件在conf這個目錄裡面:
/usr/local/nginx/conf/nginx.conf
如果你找不見也可以搜索:
find / | grep nginx.conf

『伍』 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 #顯示啟動失敗的服務

『陸』 怎麼編譯安裝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

『柒』 源碼安裝nginx需要安裝哪些東西

nginx配置裡面配置一個server段,然後把網站的目錄,域名,別名等配置好就可以了。想要好管理配置,用include加個文單花廁拘丿餃搽邪敞矛件,裡面專門配置server段

『捌』 給已經編譯安裝好的Nginx添加模塊,是要重新再編譯安裝一次嗎

編譯信息
configure arguments: --user=w /usr/local/nginx --with-pcre=/tmp/pcre-8.30 --with-http_gzip_static_mole

我現在想添加–with-http_stub_status_mole模塊,必須要重新編譯一次然後make && make install嗎?

『玖』 編譯安裝nginx和yum安裝nginx有什麼區別

如果真的要說區別的話,源碼編譯安裝可以在各個linux系統下使用,而yum安裝只能在redhat或centos系統使用,其它系統例如ubuntu,freebsd是不可用的。另外yum安裝的nginx版本偏低,而源碼包是可以獲取官方最新的發行版本的。

熱點內容
安卓手機請輸入密碼在哪裡 發布:2024-10-18 14:13:28 瀏覽:645
設計編譯程序注意的問題 發布:2024-10-18 14:08:43 瀏覽:254
傳智播客android視頻 發布:2024-10-18 14:04:42 瀏覽:904
手機版安卓吃雞哪個好 發布:2024-10-18 14:01:40 瀏覽:491
編程自學入門教程 發布:2024-10-18 13:50:58 瀏覽:141
伊迪阿明訪問中國 發布:2024-10-18 13:49:54 瀏覽:10
人三琳外傳腳本 發布:2024-10-18 13:38:16 瀏覽:839
電腦發件箱伺服器錯誤怎麼弄 發布:2024-10-18 13:30:36 瀏覽:914
evm部署solc編譯文件 發布:2024-10-18 13:29:47 瀏覽:835
android發送at指令 發布:2024-10-18 13:14:18 瀏覽:659