Nginx多種安裝方式
不指定參數配置的Nginx編譯安裝
./configure
make
make install
wget下載或瀏覽器下載上傳。解壓進入目錄
[root@mcw1 nginx-1.10.2]# ls #查看文件
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@mcw1 nginx-1.10.2]# file configure #這是個 shell腳本
configure: POSIX shell script, ASCII text executable
[root@mcw1 nginx-1.10.2]# ./configure #直接執行,會先做檢查,查到沒有的庫,報錯
checking for OS
+ Linux 3.10.0-693.el7.x86_64 x86_64
checking for C compiler … found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
checking for gcc -pipe switch … found
checking for -Wl,-E switch … found
checking for gcc builtin atomic operations … 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 module requires the PCRE library.
You can either disable the module by using –without-http_rewrite_module
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.
[root@mcw1 nginx-1.10.2]# yum install pcre pcre-devel -y #缺少依賴,安裝依賴
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
epel/x86_64/primary_db | 7.0 MB 00:00:00
Package pcre-8.32-17.el7.x86_64 already installed and latest version
Resolving Dependencies
–> Running transaction check
—> Package pcre-devel.x86_64 0:8.32-17.el7 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
============================================================================================
Package Arch Version Repository Size
============================================================================================
Installing:
pcre-devel x86_64 8.32-17.el7 base 480 k
Transaction Summary
=================================================================================
Install 1 Package
Total download size: 480 k
Installed size: 1.4 M
Downloading packages:
pcre-devel-8.32-17.el7.x86_64.rpm | 480 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pcre-devel-8.32-17.el7.x86_64 1/1
Verifying : pcre-devel-8.32-17.el7.x86_64 1/1
Installed:
pcre-devel.x86_64 0:8.32-17.el7
Complete!
[root@mcw1 nginx-1.10.2]# ./configure #繼續配置
checking for OS
+ Linux 3.10.0-693.el7.x86_64 x86_64
checking for C compiler … found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
checking for gcc -pipe switch … found
checking for -Wl,-E switch … 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 module requires the zlib library.
You can either disable the module by using –without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using –with-zlib=<path> option.
[root@mcw1 nginx-1.10.2]# yum install -y zlib-devel #2、缺啥裝啥
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
……….
Installed:
zlib-devel.x86_64 0:1.2.7-19.el7_9
Dependency Updated:
zlib.x86_64 0:1.2.7-19.el7_9
Complete!
[root@mcw1 nginx-1.10.2]# ./configure #繼續配置
checking for OS
+ Linux 3.10.0-693.el7.x86_64 x86_64
checking for C compiler … found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
checking for gcc -pipe switch … found
………
checking for zlib library … found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using system zlib library
nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin/nginx”
nginx modules path: “/usr/local/nginx/modules”
nginx configuration prefix: “/usr/local/nginx/conf”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http uwsgi temporary files: “uwsgi_temp”
nginx http scgi temporary files: “scgi_temp”
#這個配置統計出了,使用了什麼(pcre,zlib剛剛裝的兩個包),沒有使用什麼(openssl)
這裡顯示了預安裝路徑,二進位啟動文件路徑,模組存放路徑,配置存放路徑,配置文件是什麼,pid文件路徑,錯誤日誌路徑,
訪問日誌路徑,客戶端請求體臨時文件名,代理臨時文件名,fastcgi臨時文件名,uwsgi臨時文件名,scgi臨時文件名,等等
./configure執行這個配置腳本,沒加參數,默認安裝文件到上面目錄,比較分散。
[root@mcw1 nginx-1.10.2]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@mcw1 nginx-1.10.2]# make #執行make編譯命令
make -f objs/Makefile
make[1]: Entering directory `/root/nginx-1.10.2′
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
…………
-o objs/ngx_modules.o \
objs/ngx_modules.c
cc -o objs/nginx \
objs/src/core/nginx.o \
objs/src/core/ngx_log.o \
objs/src/core/ngx_palloc.o \
objs/src/core/ngx_array.o \
objs/src/http/modules/ngx_http_upstream_zone_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lpcre -lz \
-Wl,-E
sed -e “s|%%PREFIX%%|/usr/local/nginx|” \
-e “s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|” \
-e “s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|” \
-e “s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|” \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/root/nginx-1.10.2′ #移除解壓的目錄
[root@mcw1 nginx-1.10.2]#
[root@mcw1 nginx-1.10.2]# ls #
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@mcw1 nginx-1.10.2]# pwd #但這個目錄還是存在的
/root/nginx-1.10.2
[root@mcw1 nginx-1.10.2]# which make #make命令位置
/usr/bin/make
[root@mcw1 nginx-1.10.2]# make install #安裝
make -f objs/Makefile install #製作文件
make[1]: Entering directory `/root/nginx-1.10.2′
test -d ‘/usr/local/nginx’ || mkdir -p ‘/usr/local/nginx’
test -d ‘/usr/local/nginx/sbin’ \
|| mkdir -p ‘/usr/local/nginx/sbin’
test ! -f ‘/usr/local/nginx/sbin/nginx’ \
|| mv ‘/usr/local/nginx/sbin/nginx’ \
‘/usr/local/nginx/sbin/nginx.old’
cp objs/nginx ‘/usr/local/nginx/sbin/nginx’
test -d ‘/usr/local/nginx/conf’ \
|| mkdir -p ‘/usr/local/nginx/conf’
cp conf/koi-win ‘/usr/local/nginx/conf’
cp conf/koi-utf ‘/usr/local/nginx/conf’
cp conf/win-utf ‘/usr/local/nginx/conf’
test -f ‘/usr/local/nginx/conf/mime.types’ \
|| cp conf/mime.types ‘/usr/local/nginx/conf’
cp conf/mime.types ‘/usr/local/nginx/conf/mime.types.default’
test -f ‘/usr/local/nginx/conf/fastcgi_params’ \
|| cp conf/fastcgi_params ‘/usr/local/nginx/conf’
cp conf/fastcgi_params \
‘/usr/local/nginx/conf/fastcgi_params.default’
test -f ‘/usr/local/nginx/conf/fastcgi.conf’ \
|| cp conf/fastcgi.conf ‘/usr/local/nginx/conf’
cp conf/fastcgi.conf ‘/usr/local/nginx/conf/fastcgi.conf.default’
test -f ‘/usr/local/nginx/conf/uwsgi_params’ \
|| cp conf/uwsgi_params ‘/usr/local/nginx/conf’
cp conf/uwsgi_params \
‘/usr/local/nginx/conf/uwsgi_params.default’
test -f ‘/usr/local/nginx/conf/scgi_params’ \
|| cp conf/scgi_params ‘/usr/local/nginx/conf’
cp conf/scgi_params \
‘/usr/local/nginx/conf/scgi_params.default’
test -f ‘/usr/local/nginx/conf/nginx.conf’ \
|| cp conf/nginx.conf ‘/usr/local/nginx/conf/nginx.conf’
cp conf/nginx.conf ‘/usr/local/nginx/conf/nginx.conf.default’
test -d ‘/usr/local/nginx/logs’ \
|| mkdir -p ‘/usr/local/nginx/logs’
test -d ‘/usr/local/nginx/logs’ \
|| mkdir -p ‘/usr/local/nginx/logs’
test -d ‘/usr/local/nginx/html’ \
|| cp -R html ‘/usr/local/nginx’
test -d ‘/usr/local/nginx/logs’ \
|| mkdir -p ‘/usr/local/nginx/logs’
make[1]: Leaving directory `/root/nginx-1.10.2′
[root@mcw1 nginx-1.10.2]#
[root@mcw1 nginx-1.10.2]# ls /usr/local/nginx #編譯安裝完後可以看到,默認裝到/usr/local/下了
conf html logs sbin
[root@mcw1 nginx-1.10.2]# ls /usr/local/nginx/conf/
fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf
fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default
[root@mcw1 nginx-1.10.2]# ls /usr/local/nginx/sbin/
nginx
[root@mcw1 nginx-1.10.2]# ls /usr/local/nginx/html/
50x.html index.html
[root@mcw1 nginx-1.10.2]# ls /usr/local/nginx/logs/
[root@mcw1 nginx-1.10.2]# /usr/local/nginx/sbin/nginx #啟動Nginx
[root@mcw1 nginx-1.10.2]# ps -ef|grep nginx #編譯安裝默認只有個主進程,一個工作進程
root 6558 1 0 04:17 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 6559 6558 0 04:17 ? 00:00:00 nginx: worker process
root 6563 2879 0 04:17 pts/0 00:00:00 grep –color=auto nginx
[root@mcw1 nginx-1.10.2]# netstat -lntup|grep 80 #查看服務埠
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6558/nginx: master
[root@mcw1 nginx-1.10.2]#
[root@mcw1 nginx-1.10.2]# curl 10.0.0.131:80 #本地curl檢驗
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href=”//nginx.org/”>nginx.org</a>.<br/>
Commercial support is available at
<a href=”//nginx.com/”>nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@mcw1 nginx-1.10.2]# systemctl status firewalld.service #網路查看都是通的,但是無法訪問,沒想到防火牆沒關,自以為關掉了
● firewalld.service – firewalld – dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-11-02 03:27:55 CST; 56min ago
Docs: man:firewalld(1)
Main PID: 956 (firewalld)
CGroup: /system.slice/firewalld.service
└─956 /usr/bin/python -Es /usr/sbin/firewalld –nofork –nopid
Nov 02 03:27:44 mcw1 systemd[1]: Starting firewalld – dynamic firewall daemon…
Nov 02 03:27:55 mcw1 systemd[1]: Started firewalld – dynamic firewall daemon.
Nov 02 03:27:58 mcw1 firewalld[956]: WARNING: ICMP type ‘beyond-scope’ is not supported by the kernel for ipv6.
Nov 02 03:27:58 mcw1 firewalld[956]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
Nov 02 03:27:58 mcw1 firewalld[956]: WARNING: ICMP type ‘failed-policy’ is not supported by the kernel for ipv6.
Nov 02 03:27:58 mcw1 firewalld[956]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
Nov 02 03:27:58 mcw1 firewalld[956]: WARNING: ICMP type ‘reject-route’ is not supported by the kernel for ipv6.
Nov 02 03:27:58 mcw1 firewalld[956]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
[root@mcw1 nginx-1.10.2]# systemctl stop firewalld.service #停掉防火牆,瀏覽器訪問成功。有圖
[root@mcw1 nginx-1.10.2]# ls #查看到Makefile文件存在
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@mcw1 nginx-1.10.2]# cat Makefile
default: build
clean:
rm -rf Makefile objs
build:
$(MAKE) -f objs/Makefile
install:
$(MAKE) -f objs/Makefile install
modules:
$(MAKE) -f objs/Makefile modules
upgrade:
/usr/local/nginx/sbin/nginx -t
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[root@mcw1 nginx-1.10.2]# make clean #裡面就是編譯安裝的入口,make拼接一下命令,刪掉編譯文件
rm -rf Makefile objs
[root@mcw1 nginx-1.10.2]# ls #查看已經刪掉這個文件
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[root@mcw1 nginx-1.10.2]# cd ../
[root@mcw1 ~]# ls
anaconda-ks.cfg bootime.svg nginx-1.10.2 nginx-1.10.2.tar.gz
[root@mcw1 ~]# mv nginx-1.10.2 nginx-1.10.2bak
[root@mcw1 ~]# tar xf nginx-1.10.2
tar: nginx-1.10.2: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
[root@mcw1 ~]# ls
anaconda-ks.cfg bootime.svg nginx-1.10.2bak nginx-1.10.2.tar.gz
[root@mcw1 ~]# mv nginx-1.10.2bak inginx-1.10.2bak
[root@mcw1 ~]# tar xf nginx-1.10.2.tar.gz #重新解壓Nginx包
[root@mcw1 ~]# ls
anaconda-ks.cfg bootime.svg inginx-1.10.2bak nginx-1.10.2 nginx-1.10.2.tar.gz
[root@mcw1 ~]# ls nginx-1.10.2 #查看到解壓包中本來沒有Makefile文件和objs目錄的,
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
再次執行configure腳本,可以在後面看到,創建了目錄
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using system zlib library
nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin/nginx”
nginx modules path: “/usr/local/nginx/modules”
nginx configuration prefix: “/usr/local/nginx/conf”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http uwsgi temporary files: “uwsgi_temp”
nginx http scgi temporary files: “scgi_temp”
[root@mcw1 nginx-1.10.2]# ls #執行configure腳本後Makefile文件也存在了
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@mcw1 nginx-1.10.2]# cd ../ #刪除這個目錄重新解壓
[root@mcw1 ~]# ls
anaconda-ks.cfg bootime.svg inginx-1.10.2bak nginx-1.10.2 nginx-1.10.2.tar.gz
[root@mcw1 ~]# rm -rf nginx-1.10.2
[root@mcw1 ~]# tar xf nginx-1.10.2.tar.gz
[root@mcw1 ~]# cd nginx-1.10.2/
[root@mcw1 nginx-1.10.2]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[root@mcw1 nginx-1.10.2]# make #不經歷configure腳本執行,直接make,是找不到Makefile文件的。
make: *** No targets specified and no makefile found. Stop.
./configure –prefix=/root/nginx –user=www –group=www –with-http_stub_status_module –with-http_ssl_module
指定配置參數了的編譯安裝
./configure –prefix=/root/nginx –user=www –group=www –with-http_stub_status_module –with-http_ssl_module
make
make install
[root@mcw1 ~]# rz #上傳
[root@mcw1 ~]# ls
anaconda-ks.cfg nginx-1.10.2.tar.gz
[root@mcw1 ~]# tar xf nginx-1.10.2.tar.gz
[root@mcw1 ~]# ls
anaconda-ks.cfg nginx-1.10.2 nginx-1.10.2.tar.gz
[root@mcw1 ~]# mkdir nginx #建目錄
[root@mcw1 ~]# ls
anaconda-ks.cfg nginx nginx-1.10.2 nginx-1.10.2.tar.gz
[root@mcw1 ~]# ls /root/nginx
[root@mcw1 ~]# useradd -s /sbin/nologin -M www #建用戶
[root@mcw1 ~]# cd nginx-1.10.2/
[root@mcw1 nginx-1.10.2]# pwd
/root/nginx-1.10.2
[root@mcw1 nginx-1.10.2]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[root@mcw1 nginx-1.10.2]# ./configure –prefix=/root/nginx –user=www –group=www –with-http_stub_status_module –with-http_ssl_module #配置
………
checking for OpenSSL library in /opt/local/ … not found
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, 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.
#不指定參數這個pcre pcre-devel zlib-devel 要裝,指定配置參數了需要裝openssl了
yum install openssl openssl-devel -y
[root@mcw1 nginx-1.10.2]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@mcw1 nginx-1.10.2]# ls -a /root/nginx
. ..
[root@mcw1 nginx-1.10.2]#
[root@mcw1 nginx-1.10.2]# ./configure –prefix=/root/nginx –user=www –group=www –with-http_stub_status_module –with-http_ssl_module #繼續配置
checking for zlib library … found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: “/root/nginx”
nginx binary file: “/root/nginx/sbin/nginx”
nginx modules path: “/root/nginx/modules”
nginx configuration prefix: “/root/nginx/conf”
nginx configuration file: “/root/nginx/conf/nginx.conf”
nginx pid file: “/root/nginx/logs/nginx.pid”
nginx error log file: “/root/nginx/logs/error.log”
nginx http access log file: “/root/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http uwsgi temporary files: “uwsgi_temp”
nginx http scgi temporary files: “scgi_temp”
#可以看到現在的目錄是在指定的目錄下
之前的目錄是:
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using system zlib library
nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin/nginx”
nginx modules path: “/usr/local/nginx/modules”
nginx configuration prefix: “/usr/local/nginx/conf”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http uwsgi temporary files: “uwsgi_temp”
nginx http scgi temporary files: “scgi_temp”
82 make
83 make install
[root@mcw1 nginx-1.10.2]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@mcw1 nginx-1.10.2]# cd ../nginx
[root@mcw1 nginx]# ls #成功安裝
conf html logs sbin
[root@mcw1 nginx]# ls conf/
fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf
fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default
[root@mcw1 nginx]# ls html/
50x.html index.html
[root@mcw1 nginx]# ls logs/
[root@mcw1 nginx]# ls sbin/
nginx
[root@mcw1 nginx]# ll
total 0
drwxr-xr-x 2 root root 333 Nov 1 23:26 conf
drwxr-xr-x 2 root root 40 Nov 1 23:26 html
drwxr-xr-x 2 root root 6 Nov 1 23:26 logs
drwxr-xr-x 2 root root 19 Nov 1 23:26 sbin
打包解壓到新的機器上,啟動失敗,添加用戶後,訪問頁面403禁止訪問。
[root@mcw9 ~]# ls
anaconda-ks.cfg nginx.tar.gz
[root@mcw9 ~]# tar xf nginx.tar.gz
[root@mcw9 ~]# ls
anaconda-ks.cfg nginx nginx.tar.gz
[root@mcw9 ~]# cd nginx/sbin/
[root@mcw9 sbin]# ls
nginx
[root@mcw9 sbin]# ./nginx
nginx: [emerg] getpwnam(“www”) failed
[root@mcw9 sbin]# useradd -s /sbin/nologin -M www
[root@mcw9 sbin]# ./nginx
[root@mcw9 sbin]# ps -ef|grep nginx #可以看到文件都是root,root啟動,當時編譯前 配置www用戶的程式
root 2386 1 0 07:41 ? 00:00:00 nginx: master process ./nginx
www 2387 2386 0 07:41 ? 00:00:00 nginx: worker process
root 2389 2335 0 07:41 pts/0 00:00:00 grep –color=auto nginx
[root@mcw9 sbin]# systemctl stop firewalld.service
[root@mcw9 sbin]#
如下操作之後還是403錯誤
-rw-r–r– 1 root root 2552885 Nov 1 23:38 nginx.tar.gz
[root@mcw9 ~]# ps -ef|grep nginx
root 2386 1 0 07:41 ? 00:00:00 nginx: master process ./nginx
www 2465 2386 0 07:50 ? 00:00:00 nginx: worker process
root 2513 2335 0 08:03 pts/0 00:00:00 grep –color=auto nginx
[root@mcw9 ~]# nginx/sbin/nginx -s stop
[root@mcw9 ~]# ps -ef|grep nginx
root 2516 2335 0 08:04 pts/0 00:00:00 grep –color=auto nginx
[root@mcw9 ~]# nginx/sbin/nginx
[root@mcw9 ~]# ps -ef|grep nginx
root 2518 1 0 08:04 ? 00:00:00 nginx: master process nginx/sbin/nginx
www 2519 2518 0 08:04 ? 00:00:00 nginx: worker process
root 2521 2335 0 08:04 pts/0 00:00:00 grep –color=auto nginx
改配置文件為www還是不行
[root@mcw9 conf]# vim nginx.conf
[root@mcw9 conf]# grep user nginx.conf
#user nobody;
user www;
#log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
# ‘”$http_user_agent” “$http_x_forwarded_for”‘;
[root@mcw9 conf]# cd ../sbin/
[root@mcw9 sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
^C
[root@mcw9 sbin]# ./nginx -s reload
[root@mcw9 sbin]# ./nginx -s reload
[root@mcw9 sbin]# ps -ef|grep nginx
root 2546 1 0 08:08 ? 00:00:00 nginx: master process /root/nginx/sbin/nginx -c /root/nginx/conf/nginx.conf
www 2573 2546 0 08:11 ? 00:00:00 nginx: worker process
root 2575 2335 0 08:12 pts/0 00:00:00 grep –color=auto nginx
還是得改成和啟動進程的用戶是一致的才能解決403禁止訪問的問題。
[root@mcw9 sbin]# vim ../conf/nginx.conf
[root@mcw9 sbin]# ./nginx -s reload
[root@mcw9 sbin]# ps -ef|grep nginx #工作進程名也是root即程式啟動用戶就可以訪問了
root 2546 1 0 08:08 ? 00:00:00 nginx: master process /root/nginx/sbin/nginx -c /root/nginx/conf/nginx.conf
root 2595 2546 0 08:13 ? 00:00:00 nginx: worker process
root 2599 2335 0 08:13 pts/0 00:00:00 grep –color=auto nginx
[root@mcw9 sbin]# grep root ../conf/nginx.conf
user root;
root html;
root html;
# root html;
# deny access to .htaccess files, if Apache’s document root
# root html;
# root html;
指定依賴包位置編譯安裝
有時間補充
yum安裝的直接就能用了
[root@mcw1 ~]# vim /etc/resolv.conf
[root@mcw1 ~]# yum install -y nginx
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/3): epel/x86_64/updateinfo | 1.0 MB 00:00:01
(2/3): epel/x86_64/primary_db | 7.0 MB 00:00:09
(3/3): updates/7/x86_64/primary_db | 12 MB 00:00:12
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
–> Running transaction check
—> Package nginx.x86_64 1:1.20.1-9.el7 will be installed
–> Processing Dependency: nginx-filesystem = 1:1.20.1-9.el7 for package: 1:nginx-1.20.1-9.el7.x86_64
–> Processing Dependency: libcrypto.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
–> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
–> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_1)(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
–> Processing Dependency: nginx-filesystem for package: 1:nginx-1.20.1-9.el7.x86_64
–> Processing Dependency: redhat-indexhtml for package: 1:nginx-1.20.1-9.el7.x86_64
–> Processing Dependency: libcrypto.so.1.1()(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
–> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
–> Processing Dependency: libssl.so.1.1()(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
–> Running transaction check
—> Package centos-indexhtml.noarch 0:7-9.el7.centos will be installed
—> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed
—> Package nginx-filesystem.noarch 1:1.20.1-9.el7 will be installed
—> Package openssl11-libs.x86_64 1:1.1.1g-3.el7 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================
Installing:
nginx x86_64 1:1.20.1-9.el7 epel 587 k
Installing for dependencies:
centos-indexhtml noarch 7-9.el7.centos base 92 k
gperftools-libs x86_64 2.6.1-1.el7 base 272 k
nginx-filesystem noarch 1:1.20.1-9.el7 epel 24 k
openssl11-libs x86_64 1:1.1.1g-3.el7 epel 1.5 M
Transaction Summary
===============================================================================================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 2.4 M
Installed size: 6.7 M
Downloading packages:
(1/5): centos-indexhtml-7-9.el7.centos.noarch.rpm | 92 kB 00:00:00
(2/5): nginx-filesystem-1.20.1-9.el7.noarch.rpm | 24 kB 00:00:00
(3/5): gperftools-libs-2.6.1-1.el7.x86_64.rpm | 272 kB 00:00:00
(4/5): nginx-1.20.1-9.el7.x86_64.rpm | 587 kB 00:00:00
(5/5): openssl11-libs-1.1.1g-3.el7.x86_64.rpm | 1.5 MB 00:00:00
—————————————————————————————————————————————————————
Total 1.6 MB/s | 2.4 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : gperftools-libs-2.6.1-1.el7.x86_64 1/5
Installing : 1:nginx-filesystem-1.20.1-9.el7.noarch 2/5
Installing : 1:openssl11-libs-1.1.1g-3.el7.x86_64 3/5
Installing : centos-indexhtml-7-9.el7.centos.noarch 4/5
Installing : 1:nginx-1.20.1-9.el7.x86_64 5/5
Verifying : centos-indexhtml-7-9.el7.centos.noarch 1/5
Verifying : 1:openssl11-libs-1.1.1g-3.el7.x86_64 2/5
Verifying : 1:nginx-filesystem-1.20.1-9.el7.noarch 3/5
Verifying : gperftools-libs-2.6.1-1.el7.x86_64 4/5
Verifying : 1:nginx-1.20.1-9.el7.x86_64 5/5
Installed:
nginx.x86_64 1:1.20.1-9.el7
Dependency Installed:
centos-indexhtml.noarch 0:7-9.el7.centos gperftools-libs.x86_64 0:2.6.1-1.el7 nginx-filesystem.noarch 1:1.20.1-9.el7 openssl11-libs.x86_64 1:1.1.1g-3.el7
Complete!
[root@mcw1 ~]#
[root@mcw1 ~]#
[root@mcw1 ~]# nginx
[root@mcw1 ~]# ps -ef|grep nginx
root 4477 1 0 00:17 ? 00:00:00 nginx: master process nginx
nginx 4478 4477 0 00:17 ? 00:00:00 nginx: worker process
root 4480 3830 0 00:17 pts/1 00:00:00 grep –color=auto nginx
[root@mcw1 ~]# hostname -I
10.0.0.131 172.16.1.131
[root@mcw1 ~]# systemctl stop firewalld.service
[root@mcw1 ~]# rpm -qa|grep pcre
pcre-8.32-17.el7.x86_64
[root@mcw1 ~]#