基于nginx制作文档服务器
-
安装需要的基础环境
yum install gcc-c++ yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel
-
官网找到nginx稳定的最新版本
https://nginx.org/en/download.html 稳定版本:https://nginx.org/download/nginx-1.18.0.tar.gz cd /home wget -c https://nginx.org/download/nginx-1.18.0.tar.gz
-
解压压缩包数据
tar -zxvf nginx-1.18.0.tar.gz cd nginx-1.18.0
-
配置服务并编译安装
./configure make make install 查找nginx配置位置 whereis nginx
-
启动停止nginx
cd /usr/local/nginx/sbin/ ./nginx ./nginx -s stop ./nginx -s quit ./nginx -s reload 测试nginx配置是否错误 ./nginx -t 查询nginx进程: ps aux|grep nginx
-
设置开机自启动
vi /etc/rc.local #增加一行代码 /usr/local/nginx/sbin/nginx #设置执行权限 chmod 755 /etc/rc.local
-
配置文档服务
server { listen 80; server_name localhost; root /home/www/; #charset koi8-r; #access_log logs/host.access.log main; location / { autoindex on; #开启索引功能 autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb) autoindex_localtime on; # 显示本机时间而非 GMT 时间 charset utf-8; # 避免中文乱码 #root html; #index index.html index.htm; } }
-
重启防火墙设置并开放端口限制
systemctl status firewalld systemctl start firewalld 查看所有开启的端口 firewall-cmd --list-port 永久新增端口 firewall-cmd --zone=public --add-port=80/tcp --permanent 永久删除端口 firewall-cmd --zone=public --remove-port=80/tcp --permanent 重启防火墙 firewall-cmd --reload 关闭firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动