環境:
系統:redhat6.4
IP:193.168.20
nginx版本:nginx-1.18.0.tar.gz
安裝方式:原始碼編譯安裝
安裝:
安裝ngin前,確保系統安裝了軟體庫gcc,openssl-devel,pcre-devel,zlib-devel(用于編譯安裝依賴)
在rehat6.4及redhat7以上版本,系統光碟里有這些庫,掛載安裝就好
nginx下載地址:http://nginx.org/download/nginx-1.18.0.tar.gz
1.安裝nginx
[root@redhat6 ~]# groupadd -r nginx [root@redhat6 ~]# useradd -r -g nginx -s /bin/false -M nginx [root@redhat6 ~]# tar xzf nginx-1.18.0.tar.gz [root@redhat6 ~]# cd nginx-1.18.0 [root@redhat6 nginx-1.18.0]# ./configure \ --prefix=/opt/nginx \ --conf-path=/opt/nginx/conf/nginx.conf \ --sbin-path=/opt/nginx/sbin/nginx \ --error-log-path=/opt/nginx/logs/error.log \ --http-log-path=/opt/nginx/logs/access.log \ --pid-path=/opt/nginx/run/nginx.pid \ --lock-path=/opt/nginx/run/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/opt/nginx/client/ \ --http-proxy-temp-path=/opt/nginx/proxy/ \ --http-fastcgi-temp-path=/opt/nginx/fcgi/ \ --http-uwsgi-temp-path=/opt/nginx/uwsgi \ --http-scgi-temp-path=/opt/nginx/scgi \ --with-pcre [root@redhat6 nginx-1.18.0]# make && make install
2.啟動:
[root@redhat6 ~]# yum install -y net-tools (查看埠狀態工具) [root@redhat6 ~]# netstat -ntpl |grep 80 (檢查80埠是否占用) [root@redhat6 ~]# ps -ef |grep nginx (檢查nginx是否以啟動) root 4729 4222 0 07:21 pts/2 00:00:00 grep nginx [root@redhat6 ~]# /opt/nginx/sbin/nginx [root@redhat6 ~]# netstat -ntpl |grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4734/nginx [root@redhat6 ~]# ps -ef |grep nginx root 4734 1 0 07:22 ? 00:00:00 nginx: master process /apt/nginx/sbin/nginx nginx 4735 4734 0 07:22 ? 00:00:00 nginx: worker process root 4739 4194 0 07:23 pts/1 00:00:00 grep nginx 3.訪問: [root@redhat6 ~]# iptables -F (不關防火墻,就要配置允許nignx,否則不可訪問) [root@redhat6 ~]# curl http://193.168.0.20 (下圖是windows上的訪問例子)
(注:停止&重讀組態檔)
[root@redhat6 ~]# /apt/nginx/sbin/nginx -s stop #停止服務
[root@redhat6 ~]# /apt/nginx/sbin/nginx -s reload #多載服務配置
出現多載錯誤問題:
[root@redhat ~]# /opt/nginx/sbin/nginx -s reload
nginx: [error] open() "/opt/nginx/run/nginx.pid" failed (2: No such file or directory)
使用nginx -c 指定組態檔:/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
4.怎么添加到systemctl(redhat7以上才支持):
編譯安裝的nginx需要添加rc.local
nginx.service要添加可執行權限
加入前要先停止nginx,在用systemctl啟動,不然會報錯,顯示nginx已在運行無法重啟行程
[root@redhat ~]# cd /usr/lib/systemd/system [root@redhat system]# vim nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf ExecReload=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf ExecStop=/opt/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target [root@redhat system]# chmod +x nginx.service [root@redhat system]# /opt/nginx/sbin/nginx -s stop [root@redhat system]# systemctl daemon-reload
安裝路徑要確定,一般其他日志這些都默認安裝到“安裝路徑”子目錄下面
--prefix=/opt/nginx (安裝路徑)
--conf-path=/opt/nginx/conf/nginx.conf (主組態檔路徑)
--sbin-path=/opt/nginx/sbin/nginx (2進制行程啟動路徑)
--error-log-path=/opt/nginx/logs/error.log (日志)
--http-log-path=/opt/nginx/logs/access.log (日志)
--pid-path=/opt/nginx/run/nginx.pid (行程pid路徑名)
--lock-path=/opt/nginx/run/nginx.lock
--user=nginx (運行用戶)
--group=nginx (運行組)
--with-http_ssl_module (啟用ssl模塊)
--with-http_flv_module
--with-http_stub_status_module (啟用監控狀態)
--with-http_gzip_static_module
--http-client-body-temp-path=/opt/nginx/client/
--http-proxy-temp-path=/opt/nginx/proxy/
--http-fastcgi-temp-path=/opt/nginx/fcgi/
--http-uwsgi-temp-path=/opt/nginx/uwsgi
--http-scgi-temp-path=/opt/nginx/scgi
--with-pcre
常用命令:
| 開啟nginx | /usr/local/nginx/sbin/nginx |
| 關閉nginx | /usr/local/nginx/sbin/nginx -s stop |
| 重啟nginx | /usr/local/nginx/sbin/nginx -s reload |
| 測驗配置和退出 | /usr/local/nginx/sbin/nginx -t |
| nginx組態檔 |
/usr/local/nginx/conf/nginx.conf |
如有什么細節,還請大家指出
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/270485.html
標籤:Linux
