大网数据广告活动
服务器运维问答

nginx multiple domain point to same location

· 52CE 我爱测

I have several domain names registrations like example.com example.co.uk example.net I think you get the idea. At the moment I am creating multiple server block in the nginx config file like: server { listen 80; server_name examp…

问题原文

原帖链接 · Joel Chu · CC BY-SA 3.0

I have several domain names registrations like example.com example.co.uk example.net I think you get the idea.

At the moment I am creating multiple server block in the nginx config file like:

server {
    listen 80;
    server_name example.com www.example.com 
    root /var/www/example.com/html 
}

server {
    listen 80;
    server_name example.co.uk www.example.co.uk
    root /var/www/example.com/html

}

And a few more of these. Basically they are all pointing to the same website in one folder.

My question is - could it be possible to create just server block to serve the same purpose? like

server {
     listen 80
     server_name example.com example.co.uk example.net // etc
     root /var/www/example.com/html 
}

Thanks in advance.

社区高分解答

原帖链接 · VBart · CC BY-SA 3.0

Yes, it's possible.

You can use "*", even you can use regular expression, a good solution for you could be:

server {
     listen 80
     server_name ~^example.com|example.co.uk|example.net$;
     root /var/www/example.com/html 
}

I need do something like a peopleusername.wix.com and I just should do:

server {
     listen 80
     server_name  *.wix.com;
     root /var/www/example.com/html 
}

and from the code I just can access to the full url from the request and extract the username from the url and fetch the user ID from the database and put all user configuration and data from the user togeter to show the theme and colors that the users configure

There's no magic:

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-11-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。