Nginx网站配置实操
注意:后续章节均以yum官方源安装的nginx主配置文件为例详解。
h5小游戏网站部署
# 在/nginx/conf.d下新增配置文件game.conf
cd /etc/nginx/conf.d
ll
vim game.conf
server {
listen 80;
server_name game.driveryang.com; # 服务的IP或域名
location / { # 控制网站访问路径
root /code/h5_games; # 这个目录要能找到下面这个index.html才行
index index.html; # 默认网站页面的文件
}
}
# 放置游戏源代码文件至nginx配置文件指定的目录
mkdir /code && cd /code
wget http://test.driverzeng.com/Nginx_Code/h5_games.zip
# 解压
unzip h5_games.zip
解压后:
0 ✓ 10:53:58 root@web01,172.16.1.7:/code # ll
total 18856
drwxr-xr-x 6 root root 108 May 3 2019 h5_games
-rw-r--r-- 1 root root 19304923 May 3 2019 h5_games.zip
drwxrwxr-x 3 root root 40 May 3 2019 __MACOSX
# 检查配置语法是否存在错误并重载nginx (记得每次配置完文件都要检查并重载)
nginx -t
systemctl reload nginx
# 设置windows本地DNS解析文件(只要是域名访问,就要在客户端做解析)
win+R输入drivers,在里面找