废话不多说,直接安装 系统是Centos 6.9 -64的, 内核版本2.6 root用户下安装
第一个里程:检查nginx软件是否安装
#检查nginx软件是否安装
rpm -qa nginx
netstat -lntup|grep 80
netstat -lntup|grep nginx
#安装nginx软件
mkdir /server/tools -p
cd /server/tools
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xf nginx-1.12.2.tar.gz
cd nginx-1.12.2
#进行软件的编译安装过程
01. 先要解决编译安装软件依赖问题
yum install pcre-devel openssl-devel -y
#pcre-devel 是什么?
pcre的全称为perl compatible regular expressions,中文译为“perl兼容正则表达式”
rewrite 支持正则表达式信息(perl语言正则表达式)
openssl-devel 是什么?
数据信息加密软件
https服务
02. 进行软件配置
#创建普通用户并禁止登录
useradd -s /sbin/nologin -M www
./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
#编译参数说明
--prefix=PATH set installation prefix
#指定软件安装路径,指定的路径如果不存在,会默认进行创建
--user=USER set non-privileged user for worker processes
--group=GROUP set non-privileged group for worker processes
#指定nginx工作进程的管理用户和用户组信息,指定的用户默认为虚拟用户,需要进行创建
--with-http_ssl_module enable ngx_http_ssl_module
#让nginx可以支持配置https服务
--with-http_stub_status_module enable ngx_http_stub_status_module
#启用状态模块,用zabbix监控状态信息,出图显示网站日常访问情况
03. 进行软件的编译
make
说明:编译这件事,实际上就是对语言进行了翻译
04. 进行软件的编译安装(进行软件真正安装)
make install
#创建软链接
ln -s /application/nginx-1.12.2/ /application/nginx
-f --- 当链接文件失效时,强行链接到新的文件上
#启动nginx服务
[root@web01 application]# /application/nginx/sbin/nginx
[root@web01 application]# ps -ef|grep nginx
root 14616 1 0 11:00 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
www 14617 14616 0 11:00 ? 00:00:00 nginx: worker process
打开浏览器输入ip地址进行测试
成功会看到 Welcome nginx 字母,如果没成功先ping服务端地址,如果能通查看是否启动80端口,关闭iptables 和selinux 。
查看nginx软件目录结构
conf --- nginx配置文件信息保存目录
mime.types --- 表示nginx服务可以解析的媒体资源类型文件
nginx.conf --- 表示nginx服务的主配置文件
html --- nginx网站服务站点目录
logs --- nginx服务日志信息保存目录
sbin --- nginx服务命令文件保存目录
nginx 命令如何使用
-v : show version and exit
-V : show version and configure options then exit
查看nginx软件编译安装过程中,配置参数信息
-t : test configuration and exit
类似于ansible --syntax-check对配置文件进行语法检查
-s signal : send signal to a master process: stop, quit, reopen, reload
向主进程发送信号信息:停止 平滑重启
nginx默认配置文件信息
[root@web01 conf]# grep -Ev "#|^$" nginx.conf.default >nginx.conf
[root@web01 conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm; --- 当首页文件不存在时,客户端进行访问会出现403错误
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
OK,今天就到这里,后续会写 安装nginx 的各种常见错误,以及集群搭建-优化-负载