Nginx多种安装方式

不指定参数配置的Nginx编译安装

下载地址:http://nginx.org/download/nginx-1.10.2.tar.gz

./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 {
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="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://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 ~]#

 

原文地址:https://www.cnblogs.com/machangwei-8/p/15496919.html