centosnginx源碼編譯
1. centos7圖像界面怎麼部署nginx
如果你nginx是rpm包安裝的,直接用如下命令: nginx -V 如果你是源碼包編譯安裝,假如你的安裝路徑是/usr/local/nginx,那麼你可以使用: /usr/local/nginx/sbin/nginx -V 注意是大寫的V,這樣你就可以看到nginx已經載入的模塊了。
2. 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 #顯示啟動失敗的服務
3. centos 使用yum安裝nginx後如何添加模塊
1.確認你已經安裝在用的nginx信息
nginx-V
#停掉nginx服務
servicenginxstop
#進入解壓的nginx-1.10.3目錄
cdnginx-1.10.3
#編譯./configure後面加上第1步nginx-V查看到的所有配置參數,後面加上你要加的模塊配置
./configure--prefix=/etc/nginx--sbin-path=/usr/sbin/nginx...(太長我省略了)--add-mole=/root/nginx-rtmp-mole-1.1.10
make
千萬別makeinstall
驗證新nginx是否可用驗證編譯後的nginx是否可以使用已有的配置
./objs/nginx-t
使用新nginx
備份cp/usr/sbin/nginx/usr/sbin/nginx-bak
替換cp./objs/nginx/usr/sbin/nginx
ok了,重啟nginx
servicenginxstart
祝你成功!
4. centos安裝nginx錯誤
出現這個錯誤是因為nginx的安裝目錄和解壓縮目錄選擇了同一個,並且參數沒有配置好。
舉例說明:在centos 7.2 環境下,我把nginx-1.12.2.tar.gz壓縮文件放在/opt/目錄下,tar -zxvf nginx-1.12.2.tar.gz 解壓以後出現nginx-1.12.2文件夾,mv nginx-1.12.2 nginx更改文件夾名為nginx,cd nginx進入nginx目錄,./configure --prefix=/opt/nginx 設置參數,make進行編譯,make install進行安裝,安裝的時候就會報這個錯誤。
解決方法有兩個(這里的參數只是針對解決問題,還需配合其他參數使用才不會使目錄那麼亂):
安裝目錄和解壓縮目錄不要選擇同一個,即:./configure --prefix=/usr/local/nginx
設置conf-patn參數,即: ./configure --prefix=/opt/nginx --conf-path=/opt/nginx/conf/nginx.conf
5. centos nginx 編譯提示缺少cc
yum -y install make gcc gcc-c++
既然你的gcc裝了那就是缺少gcc-c++
用yum裝上gcc-c++後再編譯試試
pcre-devel zlib-devel 還有這兩個
6. centos7 nginx 鏡像怎麼用
如果你nginx是rpm包安裝的,直接用如下命令: nginx -V 如果你是源碼包編譯安裝,假如你的安裝路徑是/usr/local/nginx,那麼你可以使用: /usr/local/nginx/sbin/nginx -V 注意是大寫的V,這樣你就可以看到nginx已經載入的模塊了。
7. 如何在linux上安裝nginx
#forcentos
yuminstall-yepel-release&&yumcleanall&&yummakecache
yuminstall-ynginx
如果編譯安裝的話需要很多依賴包。YUM安裝是最簡單的。
8. 如何在 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
9. centos 使用yum安裝nginx後如何添加模塊
【操作步驟】
確認你已經安裝在用的nginx信息