P
P
Pavel Tretyakov2015-04-27 03:15:01
linux
Pavel Tretyakov, 2015-04-27 03:15:01

How to properly set up a virtual host on Debian?

// for obvious reasons changed IP, domain, folder names, etc.
Good day classmates!
I turn to you for help! I'm getting in on the action. Available:

  • VPS with Debian
  • LAMP on it
  • domain test.ru registered on 2domains.ru

dns setup :
  • @ A 178.62.35.234
  • www A 178.62.35.234
  • * A 178.62.35.234 (just in case :-) )

In sites-available config for the site (with its link in sites-enabled):
<VirtualHost *:80>                                                                                                                      
        ServerAdmin     [email protected]                                                                                       
        ServerName      test.ru                                                                                                      
        ServerAlias     test.ru www.test.ru                                                                                       
        DocumentRoot    /var/www/test.ru/public_html                                                                                 
        <Directory />                                                                                                                   
                Options FollowSymLinks                                                                                                  
                AllowOverride None                                                                                                      
        </Directory>                                                                                                                    
        <Directory /var/www>                                                                                                            
                Options Indexes FollowSymLinks MultiViews                                                                               
                AllowOverride None                                                                                                      
                Order allow,deny                                                                                                        
                allow from all                                                                                                          
        </Directory>                                                                                                            
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/                                                                                         
        <Directory "/usr/lib/cgi-bin">                                                                                                  
                AllowOverride None                                                                                                      
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch                                                                      
                Order allow,deny                                                                                                        
                Allow from all                                                                                                          
        </Directory>                                                                 
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn                                                                                                                                        
        CustomLog ${APACHE_LOG_DIR}/access.log combined                                                                                 
</VirtualHost>

Line in hosts : 178.62.35.234 test.ru
In general, the problem is that when you go to www.test.ru , the server responds perfectly and returns /var/www/test.ru/public_html to the client (where index. php),
but if you simply go to test.ru (without www), then the contents of the /var/www/ directory are returned,
where, accordingly, in addition to test.ru, there are a bunch of other directories!
I understand that these are fundamental things, and my hands are growing out of my buttocks, damn it >< how much I didn’t dig the Internet, and how much I didn’t do alchemy with these files and parameters - everything is the same.
Help me, you bastard!
UPDATE 1
Thank you all for your time and attention. I don’t know how, but I remembered that 5 years ago I read an article on setting up virtual hosts, after spending 5 hours searching for it, I found it ...
Now sites-available/test.ru looks like this:
<VirtualHost *:80>                                                                                                                      
        ServerAdmin [email protected]                                                                                                 
        ServerName test.ru
        DocumentRoot /var/www/test.ru
                                                                                                                                        
        <Directory />                                                                                                                   
                Options FollowSymLinks                                                                                                  
                AllowOverride All                                                                                                       
        </Directory>                                                                                                                    
                                                                                                                                        
        <Directory /var/www/test.ru>                                                                                                
                Options Indexes FollowSymLinks MultiViews                                                                               
                AllowOverride All                                                                                                       
                Order allow,deny                                                                                                        
                allow from all                                                                                                          
        </Directory>                                                                                                                    
                                                                                                                                        
        ErrorLog ${APACHE_LOG_DIR}/error.log                                                                                            
                                                                                                                                        
        # Possible values include: debug, info, notice, warn, error, crit,                                                              
        # alert, emerg.                                                                                                                 
        LogLevel warn                                                                                                                   
                                                                                                                                        
        CustomLog ${APACHE_LOG_DIR}/access.log combined                                                                                 
                                                                                                                                        
</VirtualHost>

Accordingly, the directory structure became /var/www/test.ru/ -> and here is the content.
Everything worked.
Who cares here is the article -> https://clck.ru/9UgJA

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Luponos, 2015-04-27
@Bessome

<Directory /var/www>                                                                                                            
                Options Indexes FollowSymLinks MultiViews                                                                               
                AllowOverride None                                                                                                      
                Order allow,deny                                                                                                        
                allow from all                                                                                                          
 </Directory>

change to
<Directory /var/www/test.ru/public_html/www>                                                                                                            
                Options Indexes FollowSymLinks MultiViews                                                                               
                AllowOverride None                                                                                                      
                Order allow,deny                                                                                                        
                allow from all                                                                                                          
 </Directory>

if there is "www" in public_html; otherwise, this part of the config is not needed at all.
PS split
ServerAlias ​​test.ru www.test.ru into:
ServerAlias ​​test.ru
ServerAlias ​​www.test.ru

S
ShamblerR, 2015-04-28
@ShamblerR

Good afternoon, you have a fairly simple problem and in general it often pops up in the nginx + apache configuration, but in your case the easiest way would be to link to the www folder, in fact, you can do without Apache at all.
It would also be quite logical to write a config without www, since this is a level 3 domain, it looks somehow stupid to screw a crutch to a level 2 domain.
Well yes

ServerAlias www.test.ru
ServerName test.ru
DocumentRoot /var/www/test.ru

It should be enough for you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question