nginx安装配置
- 检查系统之前是否装过nginx,如果安装过就将其卸载
yum remove nginx -y
- 解决软件包的依赖问题
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl openssl-devel -y
- 下载nginx源代码
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
- 解压缩源码包
tar -zxvf nginx-1.12.0.tar.gz
- 配置,编译安装
./configure --prefix=/opt/nginx1-12/ --with-http_ssl_module --with-http_stub_status_module
make && make install
3.1 --with-http_ssl_module 安装Nginx的加密模块 支持https
3.2 --with-http_stub_status_module 安装监控模块 查看nginx运行状态
3.3 --prefix=/opt/nginx1-12 自定安装位置
- 启动nginx,进入sbin目录,找到nginx启动命令
cd sbin #里面有一个nginx脚本
./nginx #启动
./nginx -s stop #关闭
./nginx -s reload #重新加载nginx配置文件,不重启nginx
./nginx -t #检测nginx.conf语法是否正确
安装成功
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/080aad88391231d9a4aa8b0cd4bc2e81.png)
nginx软件目录结构
基于域名的虚拟主机
- 准备俩域名,在hosts文件中强制解析
- 找到windows的hosts文件,强制一个域名解析,地址: C:\windows\system32\drivers\etc\hosts
10.0.0.10 www.mytb.com
10.0.0.10 www/myjd.com
- 修改nginx.conf配置文件,写入两个server{} 标签,定义两个虚拟主机
server {
listen 80;
server_name www.mytb.com;
location / {
root /opt/static/mytb;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name www.myjd.com;
location / {
root /opt/static/myjd/;
index index.html;
}
}
- 创建虚拟主机定义的网页根目录
mkdir -p /opt/static/{mytb,myjd}
- 写入两个网站的index.html文件
cd /opt/static/myjd
touch index.html
cd /opt/static/mytb
touch index.html
- 重启nginx服务器
./nginx -s reload #这是nginx的相对路径
- 在windows中访问自己的两个虚拟主机