我有一份新工作,他们拥有AWS上的所有设置。 我们有一个testing服务器,它正在托pipe一些应用程序。
如果我去
jenkins.example.com
它转到我们正在运行的Jenkins实例。
如果我去
server.test.example.com
然后转到我们的应用程序的testing版本。
在哪里configuration(不同的“子域”的应用程序)? 它在Nginx中还是在DNS条目中? 或者两个或别的地方?
(我不是百分之百地确定我应该用这个问题,例如“子域名”,随时告诉我他们是什么)。
这取决于你想要做什么。
你所问的可能需要Nginx,而不是添加DNS条目。
CNAME DNS条目可以将某些子域redirect到某个域(但不直接指向服务器上的特定IP地址或端口)。 你只需要一个CNAME,如果你映射一个子域redirect请求到一个不同的域名(即subdomain.exampleone.com是指exampletwo.com)。
Nginx可以充当反向代理,将子域名redirect到服务器上的特定文件夹/文件或端口。 这可以从/etc/nginx/nginx.conf *, http {...}块内或/etc/nginx/sites-enabled/目录中configuration,您可以在其中为每个redirect创build单独的文件(其中隐含http {...} )。
*或者你的nginx目录所在的位置
在/etc/nginx/nginx.confredirect(到特定端口上的应用程序)的正确格式如下所示:
server { # whether you type localhost or 127.0.0.1 or something else here # depends on your servers /etc/hosts file, where you define how # the server refers to itself listen localhost:80; server_name mysubdomain.example.com; location / { proxy_pass http://localhost:MYPORTNUMBER proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
将MYPORTNUMBERreplace为运行应用程序的端口。 redirect到静态文件的过程是相似的,但不是proxy_pass,而是执行root /path/to/desired/folder 。
我没有专门尝试过,但是这应该适用于你的例子中的多级子域名,例如server.test.ourdomain.com 。