【nginx】Windows下的常见问题踩坑
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
▒ 目录 ▒
🛫 导读
需求
最近写了一个前端应用需要部署后让别人能访问想来想去还是选择了目前最强悍的nginx。
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器同时也提供了IMAP/POP3/SMTP服务。
1️⃣ 安装
打开nginx官网下载地址 http://nginx.org/en/download.html下载windows的稳定版本如下图
将下载的文件解压出来其目录结构如下
2️⃣ 中文路径
解压的目录如果包含中文将会报如下错误只需要移动到一个全英文的路径即可。
3️⃣ alias指定目录
错误及原因
当我们使用alias指定目录的时候当代码如下所示访问网站时将会返回错误码
403
。
server {
listen 18088;
server_name localhost;
location / {
alias "J:/_ALL/CODE/gitee/constellations/TaurusX/pig-ui/dist/dist";
index index.html index.htm;
}
}
上面的问题找了很久最后找到关于
alias
和root
区别的讲解才知道alias需要以/
结尾
正确示例
经过上面的分析对下面几种情况进行测试都是可以正常运行的。
server {
listen 18088;
server_name localhost;
location / {
# root "J:\\_ALL\\CODE\\gitee\\constellations\\TaurusX\\pig-ui\\dist\\dist";
# root "J:\\_ALL\\CODE\\gitee\\constellations\\TaurusX\\pig-ui\\dist\\dist\\";
# root "J:/_ALL/CODE/gitee/constellations/TaurusX/pig-ui/dist/dist/";
alias "J:/_ALL/CODE/gitee/constellations/TaurusX/pig-ui/dist/dist/";
index index.html index.htm;
}
}
📖 参考资料
- 【狂神说】Nginx最新教程通俗易懂40分钟搞定 https://www.bilibili.com/video/BV1F5411J7vK
- 【nginx】新手全面实战-Mac https://blog.csdn.net/kinghzking/article/details/128740445
- nginx官网下载地址 http://nginx.org/en/download.html
**ps**文章中内容仅用于技术交流请勿用于违规违法行为。