Want to dynamically configure virtual hosts on Nginx

Asked 2 years ago, Updated 2 years ago, 50 views

Q1.What does the link to "Additional 1: Virtual Document Routes for Apache with Nginx" do?
·It looks like it is dynamically processed using subdomains as variables, but I don't understand the contents

Would it be possible to dynamically do the following with the virtual host configuration in Q2.Nginx?
·Decided hit

http:// subdomain.domain
·Document root "/var/www/Domain/Subdomain.Domain"

·Examples

http://a.example.net
·Document root "/var/www/example.net/a.example.net"

http://b.example.net
·Document root "/var/www/example.net/b.example.net"

http://a.example.com
·Document root "/var/www/example.com/a.example.com"

http://b.example.com
·Document root "/var/www/example.com/b.example.com"

Question Background
· "I think it would be good to add one by one to ""/etc/nginx/conf.d/*.conf"", but I want to write it as efficiently as possible

"

environment
·CentOS7
·PHP-FPM

nginx

2022-09-30 11:17

2 Answers

A1: Obtain the subdomain name $subdomain of the requested host example.com, redirect to example.com if there is no content directory for the subdomain (/var/www/vhosts/$subdomain), or use the content directory for the subdomain.

A2: The site you are referring to does not provide a specific example of itself, but you can dynamically change the content directory per host by providing a folder.


2022-09-30 11:17

server_name~^(?<sub>.+)\.example\.(?<tld>.+)$;
root/var/www/example.$tld/$sub.example.$tld;


2022-09-30 11:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.