Nginx初步入门 (2)

(2)安装依赖

1)安装Nginx所需的PCRE库 安装pcre库是为了使nginx支持具备URL重写功能的Rewrite模块(伪静态)。 [root@web01 /server/tools]# yum -y install pcre pcre-devel 2)安装openssl-devel Nginx在使用https功能时要用到此模块,如果不装,安装nginx过程中,也会报错。 [root@web01 /server/tools]# yum -y install openssl openssl-devel

(3)编译安装步骤

[root@web01 /server/tools]# tar xf nginx-1.18.0.tar.gz [root@web01 /server/tools]# cd nginx-1.18.0 [root@web01 /server/tools]# useradd -s /sbin/nologin www -M #创建nginx进程使用的用户(也就是nginx启动的时候,内部是由该用户启动的) [root@web01 /server/tools]# id www [root@web01 /server/tools]# rpm -qa gcc* #需要安装gcc编译器,,没装的一定要装 gcc-c++-4.8.5-36.el7.x86_64 gcc-gfortran-4.8.5-36.el7.x86_64 gcc-4.8.5-36.el7.x86_64 [root@web01 /server/tools]# ./configure --user=www --group=www --prefix=http://www.likecs.com/application/nginx-1.18.0/ --with-http_stub_status_module --with-http_ssl_module --with-pcre #配置 #configure参数的作用 --prefix=PATH 路径 --user=USER 用户 --group=GROUP 组 --with-pcre 伪静态 --with-http_stub_status_module 状态 --with-http_ssl_module 加密 443 [root@web01 /server/tools]# make #编译,把源码编译成二进制 [root@web01 /server/tools]# make install #编译安装 [root@web01 /server/tools]# ln -s /application/nginx-1.18.0/ /application/nginx #生成软连接 [root@web01 /server/tools]# /application/nginx/sbin/nginx #启动 [root@web01 /server/tools]# netstat -lntup|grep nginx #查看启动情况 [root@web01 /server/tools]# curl -i localhost #查看返回状态码是否为200 9. Nginx目录结构说明 [root@web02 /application/nginx]# tree . ├── conf │   ├── fastcgi.conf #和动态服务的接口配置参数,配合php │   ├── fastcgi.conf.default │   ├── fastcgi_params │   ├── fastcgi_params.default │   ├── koi-utf │   ├── koi-win │   ├── mime.types #媒体类型 │   ├── mime.types.default │   ├── nginx.conf #主配置文件 │   ├── nginx.conf.default │   ├── scgi_params │   ├── scgi_params.default #和动态服务的接口配置参数 │   ├── uwsgi_params │   ├── uwsgi_params.default #和动态服务的接口配置参数,配合Python │   └── win-utf ├── fastcgi_temp ├── html #默认站点目录。 │   ├── 50x.html │   └── index.html #默认的首页,10.0.0.8不指定文件,默认加载index.html首页。 ├── logs │   ├── access.log #访问日志 │   ├── error.log #Nginx错误日志。 │   └── nginx.pid #进程号对应文件。 ├── sbin │   └── nginx #启动命令。 10. Nginx启动疑难杂症汇总 10.1 启动Nginx报错:nginx: [emerg] getpwnam("nginx") failed。 这是因为没有对应的Nginx服务用户导致的,创建一个用户即可。 10.2 如何查看Nginx编译时的参数? [root@web01 /server/tools/nginx-1.18.0]# /application/nginx/sbin/nginx -V nginx version: nginx/1.18.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --user=www --group=www --prefix=http://www.likecs.com/application/nginx-1.18.0/ --with-http_stub_status_module --with-http_ssl_module --with-pcre 10.3 浏览器、wget或者curl等软件访问不了Nginx页面。

此类问题的排查思路分为nginx服务端和客户端排查,服务端排查过程如下:

(1)首先关闭selinux [root@web01 ~]# setenforce 0 [root@web01 ~]# vim /etc/selinux/config #把SELINUX=enforcing改成SELINUX=disabled [root@web01 ~]# grep SELINUX=disabled /etc/selinux/config (2)然后检查防火墙,如下: [root@web01 ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) #表示没有开启 Docs: man:firewalld(1) (3)检查端口和进程 [root@web01 ~]# netstat -lntup|grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9458/nginx: master [root@web01 ~]# ps -ef | grep [n]ginx root 9458 1 0 20:37 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx www 9459 9458 0 20:37 ? 00:00:00 nginx: worker process (4)在服务器本地wget 测试(如果前两步灭有通过,这步就不用进行了) [root@web01 ~]# wget --2020-05-19 21:04:13-- Connecting to 192.168.1.51:80... connected. HTTP request sent, awaiting response... 200 OK Length: 612 [text/html] Saving to: ‘index.html.1’ 100%[==================================================================================================================================================>] 612 --.-K/s in 0s 2020-05-19 21:04:13 (70.4 MB/s) - ‘index.html.1’ saved [612/612] (5)查看nginx错误日志 [root@web01 ~]# cat /application/nginx/logs/error.log

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpgfpj.html