nginx server_name通配符或全部 [英] nginx server_name wildcard or catch-all
问题描述
我有一个正在运行的Nginx实例,可以为多个网站提供服务.第一个是服务器IP地址上的状态消息.第二个是admin.domain.com
上的管理控制台.这些工作很棒.现在,我希望所有其他域请求都转到一个index.php
-我有很多域和子域,因此在nginx配置中列出所有域和子域是不切实际的.
I have an instance of nginx running which serves several websites. The first is a status message on the server's IP address. The second is an admin console on admin.domain.com
. These work great. Now I'd like all other domain requests to go to a single index.php
- I have loads of domains and subdomains and it's impractical to list them all in an nginx config.
到目前为止,我已经尝试将server_name
设置为*
,但是由于无效的通配符而失败. *.*
起作用,直到我添加其他服务器块为止,然后我猜想它与它们冲突.
So far I've tried setting server_name
to *
but that failed as an invalid wildcard. *.*
works until I add the other server blocks, then I guess it conflicts with them.
在定义了其他站点之后,是否可以在nginx中运行一个包罗万象的服务器块?
Is there a way to run a catch-all server block in nginx after other sites have been defined?
N.B.我不是垃圾邮件发送者,这些都是具有有用内容的真实网站,它们只是由数据库中的同一CMS支持!
推荐答案
在全部捕获"服务器块中将侦听选项更改为此. (添加default_server
)这将获取所有未定义的连接(在指定端口上).
Change listen option to this in your catch-all server block. (Add default_server
) this will take all your non-defined connections (on the specified port).
listen 80 default_server;
如果文件或文件夹不存在,则想将所有内容推送到index.php;
if you want to push everything to index.php if the file or folder does not exist;
try_files $uri /$uri /index.php;
这篇关于nginx server_name通配符或全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!