▒ 目录 ▒
- 🛫 导读
- 需求
 
- 1️⃣ 安装
- 2️⃣ 中文路径
- 3️⃣ alias指定目录
- 错误及原因
- 正确示例
 
- 📖 参考资料
 
🛫 导读
需求
最近写了一个前端应用,需要部署后,让别人能访问,想来想去,还是选择了目前最强悍的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:**文章中内容仅用于技术交流,请勿用于违规违法行为。







![《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 9 章 答案](https://img-blog.csdnimg.cn/de24d16fb1c3466ba833ce4af4eb6d9a.png)














