服务器部署---《nginx篇》 --菜鸟慧言.md
服务器部署—《nginx篇》
汇总篇:
服务器配置篇汇总(linux)+(jdk)+(tomcat)+(mysql)+(nginx)+(redis)+(fastDFS)+(mycat)
接上篇:
服务器部署—《mysql篇》
四、nginx(安全组开启所配置端口)
创建:mkdir /opt/nginx
进入:cd /opt/nginx/
下载:
wget http://file.huijia21.com/file/nginx-1.13.0.tar.gz
解压:tar -zxvf nginx-1.13.0.tar.gz
编译:
1
2
3
4
5
6
7cd nginx-1.13.0
//安装编译源码所需要的工具和库:
yum install gcc gcc-c++ ncurses-devel perl
yum install pcre pcre-devel
yum install zlib gzip zlib-devel
//编译
./configure安装到默认位置/usr/local/nginx:
make & make install
启动
1
2
3
4
5cd /usr/local/nginx/sbin/
//启动
./nginx
//重启
./nginx -s reload虚拟主机配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42vi /usr/local/nginx/conf/nginx.conf
//在原主页server上写入:
# 虚拟主机的配置
#虚拟主机一(虚拟域名):
server {
listen 8081; #端口
server_name hhh.idse.top; #域名,虚拟机需要在windows的C:\Windows\System32\drivers\etc的hosts里面配置
#120.27.244.176 hhh.idse.top
location / {
root abc; #相当于ningx目录下的hbq目录,可以写成绝对路径 /zhiyou/java
index a.html; #默认跳转页面
}
}
#虚拟主机一(真实域名):
server {
listen 8082; #端口
server_name www.idse.top; #公网域名,配置域名解析到本机ip
location / {
root abc; #相当于ningx目录下的hbq目录,可以写成绝对路径 /zhiyou/java
index b.html; #默认跳转页面
}
}
#虚拟主机三(ip):
server{
listen 8083; #端口
server_name 120.27.244.176; #域名
location / {
root abc; #相当于ningx目录下的hbq目录,可以写成绝对路径 /zhiyou/java
index c.html; #默认跳转页面
}
}
//创建文件
mkdir -p /usr/local/nginx/abc
vi /usr/local/nginx/abc/a.html //写入aaa
vi /usr/local/nginx/abc/b.html //写入bbb
vi /usr/local/nginx/abc/c.html //写入ccc
//重启nginx
cd /usr/local/nginx/sbin/
./nginx -s reload负载均衡多服务器配置
1
2
3
4
5
6
7
8
9
10
11
12
13upstream tomcatserver1 { #后面的名字自己起的,与下面proxy_pass后面保持一致
server 120.27.244.176:8080 weight=2; #ip或者主机名都可以
#server 120.27.244.176:81;
}
server {
listen 80; #端口
server_name www.idse.top; #域名,虚拟机需要在windows的hosts里面配置
location / {
proxy_pass http://tomcatserver1; #代理,会更具名字找到上面的
}
}
接下篇:
服务器部署—《redis篇》
服务器部署---《nginx篇》 --菜鸟慧言.md
http://example.com/11367.html