This has probably been answered but I can't find a straight answer, or the ones I found don't work.
I have one domain, let's call it mydomain.com The DNS settings point two subdomains. These are staging.mydomain.com and mydomain.com. Both have an A-record pointing to same IP, lets say 8.8.8.8.
On the server (8.8.8.8) I have httpd.conf with two virtual hosts, which already create by cpanel. These are as follows:
mydomain.com
<VirtualHost 8.8.8.8:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /home/userxxx/public_html
## User ydg015 # Needed for Cpanel::ApacheConf
<IfModule mod_suphp.c>
suPHP_UserGroup userxxx userxxx
</IfModule>
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup userxxx userxxx
</IfModule>
</IfModule>
<IfModule mod_ruid2.c>
RUidGid userxxx userxxx
</IfModule>
CustomLog /usr/local/apache/domlogs/mydomain.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
CustomLog /usr/local/apache/domlogs/mydomain.com combined
# ScriptAlias /cgi-bin/ /home/userxxx/public_html/cgi-bin/
</VirtualHost>
And...
staging.mydomain.com
<VirtualHost 8.8.8.8:80>
ServerName staging.mydomain.com
ServerAlias *.staging.mydomain.com
DocumentRoot /home/userxxx/public_html/staging
UseCanonicalName Off
CustomLog /usr/local/apache/domlogs/staging.mydomain.com combined
CustomLog /usr/local/apache/domlogs/staging.mydomain.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User ydg015 # Needed for Cpanel::ApacheConf
<IfModule mod_suphp.c>
suPHP_UserGroup userxxx userxxx
</IfModule>
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup userxxx userxxx
</IfModule>
</IfModule>
<IfModule mod_ruid2.c>
RUidGid userxxx userxxx
</IfModule>
# ScriptAlias /cgi-bin/ /home/userxxx/public_html/staging/cgi-bin/
# To customize this VirtualHost use an include file at the following location
# Include "/usr/local/apache/conf/userdata/std/2/userxxx/staging.mydomain.com/*.conf"
</VirtualHost>
The problem is:
I'm using wordpress multiple site to build both site (staging and main), and the multisite provide another subdomain like http://en.mydomain.com and http://en.staging.mydomain.com
Everytime I go to en.mydomain.com or en.staging.mydomain.com, I always land on "cgi-sys/defaultwebpage.cgi" someone told me, maybe I should make a change on the http.conf, but I don't know what should I change.
can anybody help me to fix this?
Any suggestions would be so appreciated. Thanks you!
The code given in these two virtual hosts are fine, but there could be another configuration in which might causing this behavior.
You should use following command to identify the correct document root.
httpd -t -D DUMP_VHOSTS
Note: httpd needs to be replaced with correct executable for your environment, for example apache2 or apachectl
Share the output of this command in case if you still not able to understand the issue.
Related
I was browsing the internet and I do not know what's going on anymore.
I have a vps with Centos webpanel, on vps is a script that is supposed to automatically create subdomains for users who want to add their business card.
Domain in OVH, I added in the dns zone entry: * .mysite.eu A IP vps.
File /usr/local/apache/conf.d/vhosts.conf
ServerName myserver
ServerAlias *.mysite.eu
ServerAlias www.mysite.eu
ServerAdmin webmaster#mysite.eu
DocumentRoot /home/lupus/public_html
UseCanonicalName Off
ScriptAlias /cgi-bin/ /home/lupus/public_html/cgi-bin/
# Custom settings are loaded below this line (if any exist)
# Include "/usr/local/apache/conf/userdata/lupus/mysite.eu/*.conf
<IfModule mod_userdir.c>
UserDir disabled
UserDir enabled lupus
</IfModule>
<IfModule mod_suexec.c>
SuexecUserGroup lupus lupus
</IfModule>
<IfModule mod_suphp.c>
suPHP_UserGroup lupus lupus
suPHP_ConfigPath /home/lupus
</IfModule>
<Directory "/home/lupus/public_html">
AllowOverride All
</Directory>
When trying to create a business card, the address is: https: //mysite.eu/company/%26nbsp%3B (after these strange characters, I can enter the name of the company)
And it should be: https: //company/mysite.eu
What is wrong?
I have already sent a feature request to CWP team for this feature.
Anyhow, for the time being now, you can create wildcard subdomain through this code. Paste this code at the end of /usr/local/apache/conf.d/vhosts.conf file through SSH or file manager
# vhost_start *.yourdomain.com
ServerName _wildcard_.yourdomain.com
ServerAlias *.yourdomain.com
ServerAdmin hostinpk#gmail.com
DocumentRoot "/home/yourdoma/public_html"
ErrorLog "/home/yourdoma/public_html/error.log"
ScriptAlias /cgi-bin/ /home/yourdoma/public_html/cgi-bin/
# Custom settings are loaded below this line (if any exist)
# Include "/usr/local/apache/conf/userdata/yourdoma/*.yourdomain.com/*.conf
SuexecUserGroup yourdoma yourdoma
suPHP_UserGroup yourdoma yourdoma
<Directory "/home/yourdoma/public_html">
AllowOverride All
# vhost_end *.yourdomain.com
Don't forget to replace yourdomain.com with your own domain name and yourdoma with the user name of the account.
Save the file and start using wildcard subdomains on your account.
I'm using apache 2.2.15, in a virtual machine over CentOS 6, I have a symfony proyect working here and my boss want to load a wordpress website in the same server on a subdomain.
Subdomain is not working, I've tried a lot of configurations, this is the last one used:
mysite.cl.conf (in /etc/httpd/conf.d folder)
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html/symfonyProyect/web
ServerName mysite.cl
ServerAlias mysite.cl
ErrorLog /var/log/httpd/symfonyProyect_error.log
CustomLog /var/log/httpd/symfonyProyect_access.log combined
<Location />
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /app.php [L]
</IfModule>
DirectoryIndex app.php
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerName mysubdomain.mysite.cl
DocumentRoot /var/www/html/mysubdomain
<Directory /var/www/html/mysubdomain>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/mysubdomain_error.log
CustomLog /var/log/httpd/mysubdomain_access.log combined
</VirtualHost>
my hosts file (in /etc folder)
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
myip mysite.cl mysubdomain.mysite.cl
and my hosts.conf
multi on
when I try mysite.cl it shows the symfony website, but when I try mysubdomain.mysite.cl, it gives me the "This site can't be reached" or "ERR_NAME_NOT_RESOLVED".
The if I delete the first VirtualHost block, it showsme the wordpress website ( even using ServerName mysubdomain.mysite.cl).
Am I missing some configuration or something??
The error you are getting is a DNS one not one from Apache. You need to modify the hosts file on same machine you are trying to browse to mysubdomain.mysite.cl.
Open a command prompt/shell on the machine you are running your browser on and just run ping mysubdomain.mysite.cl if it works your browsing should work too. If you get a message something like ping: unknown host mysubdomain.mysite.cl (Linux) or Ping request could not find host mysubdomain.mysite.cl (Windows). then simply edit the hosts file on that system or get a DNS entry added to your name server.
Simply editing /etc/hosts on the server that Apache runs on doesn't cause all other hosts to be able to resolve a hostname to an IP address.
I have a Wordpress website running on Lamp Server on Ubuntu Server 14.04.
I just tried to use the option for Post Name permalinks, and now my pages no longer load up.
I turned on the mod_rewrite function of the Apache server, restarted it, but it still doesn't work.
Also, here's my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Note that the content of /wordpress folder has been put directly inside /html
Let's say the name of my website is mywebsite.com.
How can I make it work?
EDIT: Here is my /etc/apache2/sites-available/000-default.conf file
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I found a fix. So happy!
In short, the fix for me was to go into the WordPress admin dashboard, go to:
“Settings” > “Permalinks” > “Common settings”, and set the radio button to “Custom Structure”
, and paste into the text box:
/index.php/%year%/%monthnum%/%day%/%postname%/
, and click the Save button
have you enabled the use of .htaccess like described here ?
https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles
For those running apache 2.4 and not finding "default" look in /etc/apache2/apache2.conf and edit
Directory
AllowOverride All
Directory
Directory /var/www/>
AllowOverride All
Directory
edit .ht_access
insert this line in IfModule mod_rewrite.c
RewriteRule ^(.*)$ index.php?_REQUEST=$1 [L]
IT work for me.
All requests go through the file web / app.php (similar to index.php), such as a request to the main page - adwords-up.com/web/app.php, input - adwords-up.com /web/app.php/login. I want part of the web / app.php removed from the link. In the configuration .htaccess, redirect to the default web / app.php, so that a request for such was the main form - http://adwords-up.com/, and Page login - http://adwords-up.com/login.
There is my /etc/apache2/sites-available/adwords-up.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port t$
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName adwords-up
ServerAdmin webmaster#localhost
DocumentRoot /var/www/adwords-up/web
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
this might help you
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the startpage because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
</IfModule>
add this to your .htaccess and be sure to have rewriteEngine activated
also this is a common question with answers even on the symfon2 doc
You need to set up apache virtual host and put the correct document root and rewrite rules.
example:
<VirtualHost *:80>
ServerName adwords-up.com
DocumentRoot <path-to-your-codebase>/web
DirectoryIndex app.php
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
RewriteEngine on
RewriteOptions Inherit
RewriteRule ^/app.php/(.*) http://adwords-up.com/$1
RewriteRule ^/(.*) /app.php/$1 [QSA,L]
<Directory "<path-to-your-codebase>/web">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
Hope it helps
I'm trying to setup my site to use www only, and non-www should be permanently redirected to www. This answer suggested using two virtual hosts, however it causes me to go into a redirect loop.
Here's the configuration for the site:
<VirtualHost *:80>
ServerName www.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/me/sites/mydomain.com/htdocs
# Log file locations
LogLevel warn
ErrorLog /home/me/sites/mydomain.com/logs/error.log
CustomLog /home/me/sites/mydomain.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName mydomain.com
Redirect permanent / http://www.mydomain.com/
</VirtualHost>
When I visit the non-www version of the site it successfully redirects to the www version, however Chrome then tells me that there was a redirect loop.
At first I thought it could be .htaccess in my document root however after removing that file it still happens. It's just a simple Wordpress site.
Can anyone see something wrong with the config that would cause this to happen? If not, how can I narrow down the cause?
You don't need a separate VirtualHost entry for non-www and use ServerAlias instead. Also to redirect to www just use a rule like this:
<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/me/sites/mydomain.com/htdocs
# Log file locations
LogLevel warn
ErrorLog /home/me/sites/mydomain.com/logs/error.log
CustomLog /home/me/sites/mydomain.com/logs/access.log combined
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>