@yanglt7
2018-10-21T15:53:44.000000Z
字数 5509
阅读 735
Web集群实战
[root@ylt001 ~]# yum -y install pcre pcre-devel
[root@ylt001 ~]# rpm -qa pcre pcre-devel
[root@ylt001 ~]# yum -y install openssl openssl-devel
[root@ylt001 ~]# rpm -qa openssl openssl-devel
[root@ylt001 ~]# mkdir -p /home/ylt/tools
[root@ylt001 ~]# cd -p /home/ylt/tools
[root@ylt001 ~]# wget -q http://nginx.org/download/nginx-1.14.0.tar.gz
[root@ylt001 ~]# ll nginx-1.14.0.tar.gz
[root@ylt001 ~]# useradd nginx -s /sbin/nologin -M
[root@ylt001 ~]# tar xf nginx-1.14.0.tar.gz
[root@ylt001 ~]# cd nginx-1.14.0
[root@ylt001 ~]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.14.0/ --with-http_stub_status_module --with-http_ssl_module
[root@ylt001 ~]# make && make install
[root@ylt001 ~]# ln -s /application/nginx-1.14.0 application/nginx
[root@ylt001 ~]# ll application/nginx
[root@ylt001 ~]# /application/nginx/sbin/nginx -t
[root@ylt001 ~]# /application/nginx/sbin/nginx
[root@ylt001 ~]# lsof -i :80
或
[root@ylt001 ~]# netstat -lnt|grep 80
或
[root@ylt001 ~]# ps -ef|grep nginx
检查 Nginx 启动的实际效果
在 Windows 下:在浏览器输入 IP 地址
在 Linux 下:
[root@ylt001 ~]# wget 127.0.0.1
或
[root@ylt001 ~]# curl 127.0.0.1
[root@ylt001 ~]# cd /application/nginx/html
[root@ylt001 html]# rm -f index.html
[root@ylt001 html]# vi index.html
ngx_http_core_module | 包括一些http核心参数配置 |
---|---|
ngx_http_access_module | 访问控制模块 |
ngx_http_gzip_module | 压缩模块,优化 |
ngx_http_fastcgi_module | Fast_cgi 模块,和动态应用相关 |
ngx_http_proxy_module | 代理模块 |
ngx_http_upsteam_module | 负载均衡模块 |
ngx_http_rewrite_module | URL 地址重写模块 |
ngx_http_limit_conn_module | 限制用户并发连接、请求模块 |
ngx_http_limit_req_module | 限制用户请求速率模块 |
ngx_http_log_module | 用户访问日志模块 |
ngx_http_auth_basic_module web | 访问认证模块 |
ngx_http_ssl_module | ssl 模块,用于 https 连接 |
ngx_http_stub_status_module | 记录 Nginx 基本访问状态信息等模块 |
[root@ylt001 ~]# yum install tree -y
[root@ylt001 ~]# tree /application/nginx/
基于域名的虚拟主机
基于端口的虚拟主机
基于 IP 的虚拟主机
[root@ylt001 ~]# cd /application/nginx/conf
[root@ylt001 conf]# diff nginx.conf.default nginx.conf
// 过滤包含 # 号和空行
[root@ylt001 conf]# egrep -v "#|^$" nginx.conf.default >nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalived_timeout 65;
Server {
listen 80;
server_name www.yangyangyang.org;
location / {
root html/www;
index.html index.htm;
}
}
}
[root@ylt001 conf]# mkdir ../html/www -p
[root@ylt001 conf]# echo "http://www.yangyangyang.org" >../html/www/index.html
[root@ylt001 conf]# cat ../html/www/index.html
[root@ylt001 conf]# ../sbin/nginx -t
[root@ylt001 conf]# ../sbin/nginx -s reload
[root@ylt001 conf]# lsof -i :80
或
[root@ylt001 conf]# netstat -lnt|grep 80
或
[root@ylt001 conf]# ps -ef|grep nginx
[root@ylt001 conf]# echo "192.168.2.129 www.yangyangyang.org" >>/etc/hosts
[root@ylt001 conf]# tail -1 /etc/hosts
[root@ylt001 conf]# curl www.yangyangyang.org
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalived_timeout 65;
Server {
listen 80;
server_name www.yangyangyang.org;
location / {
root html/www;
index.html index.htm;
}
}
Server {
listen 80;
server_name bbs.yangyangyang.org;
location / {
root html/bbs;
index.html index.htm;
}
}
Server {
listen 80;
server_name blog.yangyangyang.org;
location / {
root html/blog;
index.html index.htm;
}
}
}
[root@ylt001 conf]# .mkdir -p ../html/bbs ../html/blog
[root@ylt001 conf]# echo "http://bbs.yangyangyang.org" >../html/bbs/index.html
[root@ylt001 conf]# echo "http://blog.yangyangyang.org" >../html/blog/index.html
[root@ylt001 conf]# cat ../html/bbs/index.html
[root@ylt001 conf]# cat ../html/blog/index.html
[root@ylt001 conf]# LANG=en
[root@ylt001 conf]# tree ../html
[root@ylt001 conf]# ../sbin/nginx -t
[root@ylt001 conf]# ../sbin/nginx -s reload
[root@ylt001 conf]# tail -1 /etc/hosts
[root@ylt001 conf]# curl www.yangyangyang.org
[root@ylt001 conf]# curl blog.yangyangyang.org
[root@ylt001 conf]# curl bbs.yangyangyang.org
[root@ylt001 conf]# /bin/cp nginx.conf nginx.conf_BaseName
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalived_timeout 65;
Server {
listen 80;
server_name www.yangyangyang.org;
location / {
root html/www;
index.html index.htm;
}
}
Server {
listen 81;
server_name bbs.yangyangyang.org;
location / {
root html/bbs;
index.html index.htm;
}
}
Server {
listen 82;
server_name blog.yangyangyang.org;
location / {
root html/blog;
index.html index.htm;
}
}
}
[root@ylt001 conf]# ../sbin/nginx -t
[root@ylt001 conf]# ../sbin/nginx -s reload
[root@ylt001 conf]# lsof -i :80
或
[root@ylt001 conf]# netstat -lnt|grep 80
或
[root@ylt001 conf]# ps -ef|grep nginx
浏览器访问如下 3 个地址:
http://www.yangyangyang.org:80
http://bbs.yangyangyang.org:81
http://blog.yangyangyang.org:82