fe-notes
fe-notes copied to clipboard
开发环境配置域名
开发模式下每次都需要输入 IP,实在不太方便。于是通过 switchhosts 配置了如下域名:
127.0.0.1 dev.fe.com
启动服务后,可以通过域名访问项目,但是还需要跟上端口号。为了隐藏端口号,需要在 nginx 配置信息:
server {
listen 80;
server_name dev.fe.com;
location / {
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8081/;
}
}
通过 http 访问的默认端口是 80,再代理到本地 IP 目标端口即可。重启 nginx 后访问域名,就可以显示项目了,此时的 8081 端口号就被隐藏了。
nginx 用作静态资源服务,访问 markdown 文件会直接提示下载,这是因为浏览器没法解析,一般需要代理转发然后通过一些工具比如 pandoc 转为 html 文件。