Good pratice for multiple domains on the same server [closed] - apache

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have multiple domains going to the same IP / server (I do shared hosting of multiple domains on my own server). I would like :
http://domain1.com/* => /var/www/domain1/*
http://domain2.com/* => /var/www/domain2/*
Up to now I do it with PHP : all requests are sent to a single PHP file that does the redistribution :
if (strpos($_SERVER['HTTP_HOST'], 'domain1') !== false)
// call the file in /var/www/domain1/*
if (strpos($_SERVER['HTTP_HOST'], 'domain2') !== false)
// call the file in /var/www/domain2/*
I can imagine that there exists a "cleaner" solution without PHP, but just .htaccess ?
What is the best pratice for having multiple domains going to the same server? How should I route the requests from multiple domains to the right directory of the server?
Note : I found this but as there is only 1 upvote, I'm not sure if this is really relevant.

You can use VirtualHosts to route certain sites to directories.
Here's the general configuration I use (in httpd.conf - there's loads of other info here):
<VirtualHost *:80>
ServerName mydomain.example.com
DocumentRoot /var/www/mydomain.example.com
</VirtualHost>
You can also place these directives in different files in /etc/apache2/sites-available/<name>.conf and then do a2ensite <name>, if you're on a system that supports that (Debian/Ubuntu IIRC).

Related

How can I prevent apache to log Health Checks in Docker? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have a dockerized web application deployed, and everything works just fine, logging every request, including a HUGE number of health checks, which are configured to hit the page /health, a blank page.
I think it's a common problem, and I found this question for a different stack (Elastic Beanstalk).
I'd like to have a solution that is completely automatic and possibly in the Dockerfile
First of all, I need an additional configuration file for Apache, let's call it apacheLogFilter.conf.
The content will be pretty easy, but it could be customized as much as we want, defining custom rules. The trick is defining a custom environment variable that, if present, will stop the logging for that request
SetEnvIf Request_URI "^/health$" dontlog
Once defined this new configuration, we need to plug it into apache directly in the Dockerfile, adding the following rows:
FROM php:7.2-apache
...
# Copy the log-filtering configuration in the right place
COPY apacheLogFilter.conf /etc/apache2/conf-enabled
# Change the standard logging entry of all the available sites to use the variable
RUN sed -ri -e 's!combined!combined env=\!dontlog!g' /etc/apache2/sites-available/*.conf
...
In this way, the configuration file will be loaded by apache at startup, each request will check the rules defined, and in case one of them will trigger, the request will not be logged

What is the difference between configuring SSL in nginx.conf or in sites-enabled? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I configured SSL in my nginx.conf. I'm getting a valid certificate on https://www.mydomain.com however, this shows a 404 as my website is at mydomain.com
Exploring, I see my site inside of available-sites which has a server block with a root and index but not listen block.
What is the difference between these two?
You can place your SSL configuration into either file. If you check the bottom of nginx.conf you will see
include /etc/nginx/sites-enabled/*;
Which simply includes the contents of all config files in sites-enabled into nginx.conf and continues parsing.

How to add a custom variable with apache logs? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
How to add custom variable name with apache logs so that I can add my project name with my error logs in beginning, it is helpful for recognizing error logs with project name. I have lot of projects in my organization and project can be build in any language, I want to track all logs on a one place, but issue is that which errors are coming from which projects, i am unable to get it, so I want to add project name with logs. please suggest me, if any documentation is there, so i can manipulate apache then share with me.
Apache Access Log is using a log format defined by LogFormat directive.
This format can contain a lot of things. One of theses things is %{VARNAME}e : The contents of the environment variable VARNAME. So using SetEnv on your application VirtualHosts you could manage your goals.
But this does not work for ErrorLog. If you manage applications with Virtualhosts you should use separate ErrorLog files on theses Virtualhosts.

Special configuration of the vhost [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I've got some headache trying to configure that for some days so I hope someone can help me.
I've got few sites, each one related to an FTP account. I would like to make them accessible through my man website by the url http://www.mainsite.com/site1. At this point an Alias should do the work.
However I would like to add some features such as specify the log file related to the site1 which would be in the web directory of the FTP account site1. Later, I would like to put them in /var/log and have a script to sync the log file located in the web directory with the one in /var/log so that even if a user delete the log file in the web directory, the original one is still here.
To go back to the main problem, I don't know how to do that, I tried to configure a whole vhost for the site1 but then, as the ServerName would be the same as the main site, the main site would no longer be accessible.
Any suggestions ?
You could try the ancient ServerPath directive, which will cause /site1 to be mapped to one vhost and /site2 to be mapped to another, despite having matching servername and local interface:port.

Apache wildcard at domain level [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have few sites, and they all have identical setup on a single server. Now, instead of the separate configuration file for each of them in sites-enabled directory, I want to have a common file.
Idea is this:
www.abc.com should have /var/www/abc as DocumentRoot,
www.xyz.com should have /var/www/xyz as DocumentRoot, etc.
All other parameteres like log files, contact emails etc should also have identical setup (abc.com should have contact#abc.com as admin email, xyz.com should have contact#xyz.com as admin email etc).
I couldnt find any tutorial on how to backreference wildcards, etc.
regards,
JP
Aha. Found the solution. VirtualDocumentRoot is the answer.
A single line like:
VirtualDocumentRoot /var/www/%0
does the job. Havent really figured the logs stuff but should be similar and easy.
See https://serverfault.com/questions/182929/wildcard-subdomain-directory-names for a nice related thread.
You gotta enable vhost_alias module for this. (sudo a2enmod vhost_alias on ubuntu).