Welcome! Log In Create A New Profile

Advanced

Problem with subdomain wildcard and localhost

Posted by NginxNewComer 
Problem with subdomain wildcard and localhost
December 28, 2013 01:52PM
Hello

I wish to have a configuration which allows for subdomains to be accessable without actual real sub folders created.

Example

jack.localhost, this would be the direct url, but nginx would parse it as localhost/?query=jack
steven.localhost -> localhost/?query=steven.

I have tried loads of rewrite rules, via server_name, and location, but none seem to work.
Im sure I must be missing something here.

Thanks in advance for any reply.



Edited 1 time(s). Last edit at 12/28/2013 01:53PM by NginxNewComer.
Re: Problem with subdomain wildcard and localhost
December 29, 2013 01:44PM
Hello

I believe I have managed to partially solve this(within my own knowledge of things)

Firstly, Within your hosts file(independant of nginx) you must setup some subdomains, For windows it will originally look something like this

Before
127.0.0.1 localhost
After
127.0.0.1 localhost test.localhost example.localhost

Now in your nginx.conf file, Setup your server block like this.

server {
listen 80;
server_name ~(?<subdomain>.*).localhost;

You will now be able to access either localhost,test.localhost, or example.localhost, if you need the subdomain name in the url, you can access it via $subdomain.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 171
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready