本文主要介紹,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
訪問示例