Linux配置Nginx服务器

配置Nginx简介

与Apache类似,Nginx支持多种虚拟机配置方式,如基于IP地址的虚拟主机和基于域名的虚拟主机配置,本篇博客主要以基于域名的虚拟主机配置为例。
安装Nginx服务器:https://blog.csdn.net/qq_46323758/article/details/116351553

配置Nginx服务器

一、配置IP地址

1、配置IP地址

ifconfig ens33 192.168.100.100

二、新建目录及配置文件

1、新建目录:在/usr/local/nginx/conf目录下新建目录vhost

cd /usr/local/nginx/conf
mkdir vhost

2、在vhost目录中新建虚拟主机配置

cd vhost
vim exam.conf

3、设置配置文件内容

server{
		listen 192.168.100.100:80;
		server_name http://exam.excesoft.com;
		access_log /data/logs/http://exam.excesoft.com.log main;
		error_log /data/logs/http://exam.excesoft.com.errror.log;
		location /{
		root /var/www/html/exam;
		index index.html index.htm;
	}
}

4、将虚拟主机配置文件包含到主文件中

vim nginx.conf

在nginx.conf文件末尾的最后一个花括号内部,增加下列语句:include vhost/*.conf

	include vhost/*.conf;
}

三、创建日志文件

1、创建目录

mkdir /data/logs

2、创建日志文件

touch  /data/logs/http://exam.excesoft.com.log

3、创建错误日志

touch  /data/logs/http://exam.excesoft.com.error.log

四、进行Nginx服务器的测试

1、检查服务器配置

cd /usr/local/nginx/sbin/
./nginx -t

2、启动nginx服务器

./nginx

3、添加域名和IP地址的对应关系

vim /etc/hosts

在最后一行添加内容

192.168.100.100 http://exam.excesoft.com

五、创建目录及测试文件

1、创建目录

mkdir -p /var/www/html/exam

2、创建测试文件

vim /data/exam.excesoft.com/index.html

3、在index.html中输入

hello,this is index.html in /data/exam.excesoft.com/

4、启动浏览器,输入http://192.168.100.100,可看到Nginx服务器的主页显示内容为首页内容

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值