时间:2023-07-16 00:48:01 | 来源:网站运营
时间:2023-07-16 00:48:01 来源:网站运营
Centos8 Yum安装nginx并设置虚拟主机:nginx是最近非常火的web服务器,这次CentOS8也在yum官方源中新增了nginx 1.14dnf install nginx -y
如果出错检查检查一下网络和yum源,如何更换yum源到阿里源vim /etc/nginx/nginx.conf
可以看到里面有个默认网站,不用管它,在红色箭头处插入两个网站的配置server { listen 80; listen [::]:80; access_log /usr/share/nginx/log/game.shaochenfeng.com; error_log /usr/share/nginx/log/game.shaochenfeng.com.err error; server_name game.shaochenfeng.com; root /usr/share/nginx/game.shaochenfeng.com; location / { } }server { listen 80; listen [::]:80; access_log /usr/share/nginx/log/map.shaochenfeng.com; error_log /usr/share/nginx/log/map.shaochenfeng.com.err error; server_name map.shaochenfeng.com; root /usr/share/nginx/map.shaochenfeng.com; location / { } }
保存并退出 下面创建虚拟主机的主目录和日志目录mkdir /usr/share/nginx/game.shaochenfeng.com # 创建虚拟主机的主目录和日志目录mkdir /usr/share/nginx/map.shaochenfeng.com#将你的网站文件复制到上面对应的目录mkdir /usr/share/nginx/logchown nginx:nginx -R /usr/share/nginx/game.shaochenfeng.com # nginx运行在nginx用户下,所以要给网站文件授予权限chown nginx:nginx -R /usr/share/nginx/map.shaochenfeng.com
启动并开机启动nginxsystemctl enable nginx # 设置nginx开机启动systemctl start nginx # 启动nginxsystemctl status nginx # 查看nginx状态
这样, 当访问http://game.shaochenfeng.com时就会得到/usr/share/nginx/http://game.shaochenfeng.com/index.html 当访问http://map.shaochenfeng.com时就会得到/usr/share/nginx/http://map.shaochenfeng.com/index.html关键词:设置,虚拟,主机,安装