乐趣区

本地电脑搭建Nginx服务器

(1)Nginx 官网下载 (http://nginx.org/en/download….(2) 打开文件 nginx.conf 文件 , 做出以下修改.server {
# 启动后的端口
listen 8880;

# 启动时的地址
server_name localhost;

# 启动后,地址栏输入: localhost:8880, 默认会在 html 文件夹下找 index.html 文件
location / {
root html;
index index.html;
}

# 404 页面配置,页面同样在 html 文件夹中
error_page 404 /404.html;
location = /404.html {
root html;
}

# 其他错误码页面配置
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# 配置代理。由于项目是在本地起动的,而我们的 request 需要请求其他 ip 地址。如果你的 request 链接为 localhost:8880/abc/login?name=12345, 那么下面配的就是 location /abc
location /api {
proxy_pass http://192.168.0.0:80;
}

# 一把前端不管用 vue,还是 react 等框架,默认都是单页面的,如果你的项目是多页面的,则需要用到下面的配置。
# 因为此时你的浏览器的 url 不是 localhost:8880/#/login, 而是 localhost:8880/a.html/#/login
# 所以我们需要将路径中 a.html 指向具体的 html 文件夹中的文件,因为默认是 index.html
location /a.html {
alias html;
index a.html;
}
location /b.html{
alias html;
index b.html;
}
}
(3)将编译文件放入 html 文件夹里面 (4) 启动服务器 $start nginx 关闭 $nginx -s stop 浏览器打开 localhost:7777 或者通过任务管理器关闭.

退出移动版