本文主要介绍,linux环境下使用 Nginx部署静态页面的使用
1.新建 index.html
<html>
<head>
<title>Nginx-demo</title>
</head>
<body style="padding: 20px;">
<br/>
<p>Nginx 静态 Html hello world ......</p>
</body>
</html>
2.上传html到目录
cd /usr/local;
mkdir nginx-web-demo;
3.配置nginx.conf
注:该配置文件在conf文件夹下 。示例目录 /usr/local/nginx/conf/
#启动用户
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
charset utf-8; # 设置编码格式
server {
listen 8081; # 端口号
server_name _; # 配置域名信息
root /usr/local/nginx-web-demo/; # 静态页面根目录
index index.html;
}
}
4.启动与关闭
进入/usr/local/nginx/sbin目录,输入./nginx即可启动nginx
cd /usr/local/nginx/sbin
./nginx
关闭nginx
./nginx -s quit 或者 ./nginx -s stop
重启nginx
./nginx -s reload
查看nginx进程
ps -ef|grep nginx 或者 ps aux|grep nginx
5.访问测试
http://IP:8081/
图示示例
6.常见问题
6.1在启动完成之后,访问出现了403。
- 检查启动用户和nginx工作用户是否一致
- 修改nginx.conf的第一行,示例: user root,重启nginx;
7.附录域名配置
这里以内网自定义域名示例举例。
修改nginx.conf > server块 > [listen(端口)、server_name(域名)]
listen 80;
server_name test.nginx.html.demo.com;
修改host文件
注:由于使用的是内网自定义域名,所以需要配置hosts
Windows系统hosts文件所在地址:Windows\System32\drivers\etc
ios系统hosts文件所在地址:/etc/hosts
hosts文件新增
# IP 映射域名地址
172.16.21.69 test.nginx.html.demo.com
访问示例