#区别
yum:不支持定制,安装文件分散不好管理
make源码:安装复杂,模块定制,安装目录自定义,方便管理
-
预编译 生成 MakeFile 文件
-
编译生 成二进制文件 make
-
安装 指定目录 make install
#下载
wget -c http://nginx.org/download/nginx-1.18.0.tar.gz -c 断点下载
tar zxf nginx-1.18.0.tar.gz
cd nginx-1.18.0/
#依赖
yum install -y gcc 「c编译器」
yum install -y gcc-c++ 「c++编译器」
yum install -y pcre pcre-devel 「重写」
yum install -y zlib zlib-devel 「gzip压缩」
yum install -y openssl openssl-devel 「https安全协议」
find / -name '*pcre*.so’ 「库文件」
#nginx安装
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module
make
make install
#目录
tree -L 2 /usr/local/nginx/
/usr/local/nginx/
├── conf
│ ├── fastcgi.conf
│ ├── 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
│ └── win-utf
├── html
│ ├── 50x.html
│ └── index.html
├── logs
└── sbin
└── nginx
#启动
/usr/local/nginx/sbin/nginx 「缺少www用户」
nginx: [emerg] getpwnam("www") failed
id www
useradd -s /sbin/nologin -M www -s, --shell -M, --no-create-home
/usr/local/nginx/sbin/nginx
ps -ef | grep nginx
netstat -lptun | grep nginx
setenforce 0 「selinux关闭」
防火墙配置80端口
#访问
#配置
vim /usr/local/nginx/conf/nginx.conf
grep -vE '#|^$' conf/nginx.conf 「去掉注释和空行」 -v 反选 -E 正则表达式
#多站点
多个站点共享一台 nginx 服务器
多端口、多IP、多域名
cp nginx.conf nginx.conf.120520
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 lc.a.com; 「站点一」
location / {
root html/lc.a.com;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name lc.b.com; 「站点二」
location / {
root html/lc.b.com;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
/usr/local/nginx/sbin/nginx -? 「帮助档」
/usr/local/nginx/sbin/nginx -t 「语法检查」
/usr/local/nginx/sbin/nginx -s reload
cd /usr/local/nginx/html
cp index.html lc.a.com
cp index.html lc.b.com
<h1>Welcome to lc.a.com!</h1>
<h1>Welcome to lc.b.com!</h1>
sudo vim /etc/hosts
10.211.55.13 lc.a.com lc.b.com