nginx安装 +多站点

#区别
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>

vim lc.b.com/index.html

<h1>Welcome to lc.b.com!</h1>

sudo vim /etc/hosts

10.211.55.13 lc.a.com lc.b.com

访问:http://lc.a.comhttp://lc.b.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值