题目可能说不清!
我这里说一下,我们的项目都是前后分离,几个项目都用的同一后端服务器,本地开发测试的时候是通过配置 nginx 来调用测试服务器的 Api 。(具体的这里也不细说了)
所以问题就来了,随着负责项目的增加,我们的 nginx 配置会出现类似这么这个情况:
location ~* ^.+\.(js|css|less|sass|map|gif)$ { #PC 静态资源 #项目 1 #root /Users/Go7hic/work/项目 1 #项目 2 root /Users/Go7hic/work/项目 2 #项目 3 #root /Users/Go7hic/work/项目 3 # 项目 4 #root /Users/Go7hic/work/项目 4 #项目 5 #root /Users/Go7hic/work/项目 5 expires 2h; } #后端服务 location ~ /{ proxy_pass http://xx.xxx.xxx:3000; }
每次我要开发测试项目 1 的时候,我又要找到 nginx.conf 来把项目 2 注释掉,而当我要修改测试项目 3 的一个 bug 时,又得把项目 1 的路径给注释掉。
觉得每次都查找修改这个文件很麻烦,所以我现在的做法就是经常把 ngnix.conf 这个文件用编辑器打开不关,觉得这个做法一点都不优雅。
现在想可不可以用 Node.js 或者其他语言来写个小工具来操作这个文件,希望各位给点建议或者分享你们的解决办法
![]() | 1 AlloVince 2015-10-21 22:30:10 +08:00 为什么不对不同的资源绑定不同的域名 |
![]() | 2 lhbc 2015-10-21 22:30:32 +08:00 via Android 多个 host 。 |
![]() | 3 zzlyzq 2015-10-21 22:34:50 +08:00 git checkout XXX |
![]() | 6 ryd994 2015-10-21 23:29:22 +08:00 文件有冲突么? 如果没有的话可以 try_files 所有的 |
![]() | 7 Showfom PRO 绑定不同域名或者不同端口啊 |
![]() | 8 cxbig 2015-10-21 23:38:19 +08:00 为每个项目文件夹做 vhost 文件,切换哪个就链接到 sites-enabled 。 |
![]() | 9 zzlyzq 2015-10-22 00:05:51 +08:00 @g0thic heihei, just use domain name . Last reply I just see you have different project at the different period, so you can use git checkout, aha~~ |
![]() | 10 randyzhao 2015-10-22 01:49:14 +08:00 恩... .../conf.d/project1.conf .../conf.d/project2.conf .../conf.d/project3.conf .../conf.d/project4.conf ... |
11 5thcat 2015-10-22 11:33:07 +08:00 可以用 ejs, 把 root 那一行 做成 <%= root_dir %> |
![]() | 12 mouer 2015-10-22 13:04:06 +08:00 ![]() nginx conf 里面可以写 if 的, if 里面判断某个文件是否存在,比如(伪代码) if 存在 /tmp/a proxy http://a if 存在 /tmp/b proxy http://b |