create subdomain in centos 6 - centos

I'm trying to create a subdomain in my virtual server (it's a centOS). I have edited the httpd.conf file like this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html/zend/
<Directory "/var/www/html/zend">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ServerName zend.mydomain.es
</VirtualHost>
When I try www.mydomain.es it's work fine, but when I try zend.mydomain.es I get Server Not Found error.
Are there any other files i must configure for this to work?

You should also setup dns for the your subdomain and make sure subdomain is pointing to the correct ip
Also check ping if it is replying:
ping zend.mydomain.es
If the IP is correct check both Apache logs (error.log and access.log).

I would recommend verifying your DNS settings for the subdomain.
E.g. If you are hosting with GoDaddy, I would recommend making sure
you have an entry for your subdomain there and that the IP points to
the same box.
Next, if you haven't yet, after you make your changes to httpd.conf
you need to restart the httpd service for the changes to take
affect. So try service httpd restart
Hopefully one of those helps solve your issue.

Related

How to run a service on subdomain instead of port on AlmaLinux with Cpanel?

I have a version of keycloak running on my AlmaLinux server. This service runs on port 8080. I can access it using <SERVER-IP>:8080. I however, want to access the service using mysubdomain.mymaindomain.com. This way, the user is not confronted with port-numbers, and I suppose using autoSSL is easier (I cannot get it to work on a different port).
I tried multiple things.
The first (I know, very sketchy) was rerouting using htaccess. I made a rewrite condition that looped to localhost:8080. At first glance this worked, but redirects did not work. I suppose this is, since the service thinks it runs on 'localhost:8080' (what it of course does), and thus redirects (on the browser side) to localhost:8080/home for example.
The second thing I tried was adding this code to the virtualhost config file.
I added this using the WHM environment in the server configuration > apache configuration > include editor. There I tried both 'Pre Virtual Host Include' and 'Post Virtual Host Include' (Originating from here).
<VirtualHost *:80>
DocumentRoot "/public_html/keycloak_public"
ServerName mysubdomain.mymaindomain.com
# Other directives here
</VirtualHost>
That did not work, I found out I had to use a proxy. So I appended the following code behind the former part. (Originating from here).
<VirtualHost *:80>
ServerAdmin me#mymaindomain.com
ServerName mysubdomain.mymaindomain.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
However, when I go to mysubdomain.mymaindomain.com this still loads the empty directory, instead of the equivalent of :8080.
According to the above mentioned thread, I have to enable proxy somehow, but I did not find a way to do so in Cpanel, so I kind of assumed it was enabled (I'm sorry). Can that be the problem, or should I look somewhere else in order to fix this problem?
The solution turned out to be replacing the * with the server-ip!

Multiple services with web based user interface in the same server

I have a server with multiple services and tools with web based user interface (rundeck, jenkins, sonarqube,...) and I want the devteam can access with a properly url, not the server IP and a port.
IE:
- companyName-rundeck.com
- companyName-jenkins.com
- companyName-sonarqube.com
What would be the best approach to do that?
What is most often use for this purpose is some kind of reverse proxy. I will describe the simple Apache setup, but it should be as easy to configure it using nginx or HAProxy.
For example purposes, let's sat that you have 3 services running on the server:
Jenkins on port 8080
SonarQube on port 9000
RunDeck on port 4440
First, in order to distinguish between services just by using domain name, you will need to create several entries in your DNS, pointing the names to the server IP address:
jenkins.example.com A 192.0.2.2
sonar.example.com A 192.0.2.2
rundeck.example.com A 192.0.2.2
Next, (if you have not already done that) install Apache HTTP server:
yum install httpd
Create a file /etc/httpd/conf.d/proxy.conf:
<VirtualHost *:80>
ServerName jenkins.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName sonar.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:9000/
ProxyPassReverse / http://localhost:9000/
</VirtualHost>
<VirtualHost *:80>
ServerName rundeck.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:4440/
ProxyPassReverse / http://localhost:4440/
</VirtualHost>
(the logic should be quite clear, for detailed explanation, look at the docs)
After that, just start the httpd service: service httpd start.
The instructions are for CentOS, but should not differ too much for other distros
In case it does not work as expected (without any obvious trace in logs) try with disabled selinux (setenforce 0 && service httpd restart)

How to access my PC localhost AND internet with my iPhone?

My Windows 10 pc has xampp installed. I use it for multiple projects so my folder structure is similar to:
xampp
|-htdocs #dummy localhost
|-htdocs-projecta
|-htdocs-projectb
|-etc
I have set up my http-vhosts.conf file and hosts file so that when I go to projecta.dev or projectb.dev then apache returns the correct website.
I have set up my pc to act as a wifi hotspot and connected my iphone to the hotspot. I have configured the wifi connection on my iphone so that my pc acts as a proxy. This means when I go to projecta.dev on my phone I can see the website from my computer.
This is where I am having problems - using this method it appears I can ONLY see websites that are on my computer (ie I am unable to download resources from other websites - such as jQuery or Analytics).
How can I set up my PC and iPhone so I can access the local project domains on my pc from my iphone, as well as having regular internet access to download other scripts?
[edit]
More info:
My vhosts file is configured like this:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\"
ServerName localhost
<Directory C:\xampp\htdocs>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs-projecta\public_html"
ServerName projecta.dev
<Directory C:\xampp\htdocs-projecta>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs-projectb"
ServerName projectb.dev
<Directory C:\xampp\htdocs-projectb>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
...
And my hosts file is:
127.0.0.1 projecta.dev
127.0.0.1 projectb.dev
...
When I access project-a.dev from my phone, it loads the website excluding third-party resources (such as Google Fonts and jQuery). When I go to Google it loads my localhost, with other pages / folders returning a 404. This led me to think the issue is with the vhosts configuration - it can't find a matching server name and is loading the default localhost.
So I changed <VirtualHost *:80> to <VirtualHost projecta.dev:80> but that had no effect. I also added Listen projecta.dev:80 but that also had effect.
How do I set up vhosts to ignore all requests that but those in the vhosts file / with ServerNames?
First, you may check whether your iPhone able to connect to any website or not after you connect to the wifi hotspot, e.g. www.google.com
If yes and you still unable to connect, you may check whether the link of the jquery script is correct or not by try on your laptop. If there having the same problem with your phone, then you inspect element and check whether the script successful download or not. Sometimes, we may put the jquery link wrongly.
If all are ok but the iPhone still cannot download it, I think you may download those jquery script and put into the htdoc folder together with your project. Actually this way can save a lots of time.
Hope this can help you!
I had set up my iphone to have a proxy connection to my pc for ALL requests.
What I had to do was create a .pac file on my pc so, on a per-request basis, it would tell my iphone whether to access my pc as a proxy or connect directly to the resource.
Here is my proxyfile.pac:
function FindProxyForURL(url, host)
{
//localhost projects
if (dnsDomainIs(host, "projecta.dev")) return "PROXY 192.168.1.87:81";
if (dnsDomainIs(host, "projectb.dev")) return "PROXY 192.168.1.87:82";
//... etc
//everything else
return "DIRECT";
}
As you can see, I am now telling my iphone to use my computer to proxy specific urls to different ports on the same ip. If I set it to port 80, then they would all access my default localhost instead of the website they are supposed to load. This meant I had update my vhosts file as well:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs-projecta\public_html"
ServerName projecta.dev
<Directory C:\xampp\htdocs-projecta>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Listen 81
<VirtualHost *:81>
DocumentRoot "C:\xampp\htdocs-projecta\public_html"
ServerName projecta.dev
<Directory C:\xampp\htdocs-projecta>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
For each project, I copy/paste the VirtualHost block, change the port and add a Listen command.
With this set up I am now able to access, on my pc and iphone http://projecta.dev, as well as the internet in general (e.g. http://google.com) so that I can download external resources as needed (such as jQuery, google fonts and so on).

What's happening with search.cpan.org and how to install an redirector?

EDITED question
It last 2 weeks search.cpan.org was down many times. Yes i know here is a metacpan, but zilion of links from the net points to search.cpan.org so the metacpan isn't the "only" solution.
Want make a local redirector, by entering to my /etc/hosts something like:
search.cpan.org 127.0.0.1
and run an simple PSGI (or Apache) server on localhost:80 what should done the redirects. So the requests for "search.cpan.org" would be processed at "localhost" with the script and it should return valid 302 responses and redirect to metacpan.org.
#Mpapec pointed to mcpan.org - what doing exactly for what i looking, so now enoudh redirect every request to "mcpan.org".
After edited my /etc/hosts as above, tried the next apache config:
<VirtualHost *:80>
ServerName search.cpan.org
RedirectPermanent / http://search.mcpan.org/
</VirtualHost>
but doesn't work. Would be nice to get some help. Or an alternative, a simple app.psgi script would be nice too.
So, the questions are:
how to configure local apache for redirects search.cpan.org -> search.mcpan.org
or how to write a simple app.psgi for running it with plackup -p 80 for the same function
and one offtopic question:
know anyone something about the status and a future of search.cpan.org?
search.cpan.org is run by Graham Barr. For questions about websites that he runs, you'll have to contact him.
The source code is not available. That's why MetaCPAN sprang up.
I wouldn't bother with a redirector. Maybe a Greasemonkey script, though :)
I was an configuration error in my apache. The next works.
1.) edit /etc/hosts and add a line IP.OF.YOUR.LOCAL.WEBSERVER search.cpan.org, e.g.:
127.0.0.1 search.cpan.org
2.) for apache (i have 2.4) into httpd.conf enter
<VirtualHost *:80>
ServerName search.cpan.org
Redirect / http://search.mcpan.org/
</VirtualHost>
3.) Be sure than your apache listening on port 80 e.g. have a directive
Listen 80
With the above, every request to "search.cpan.org" get redirected to "search.mcpan.org" and the "mcpan" redirects it to "metacpan". It is suboptimal, would be nicer to have a set of rewrite rules what redirects directly into "metacpan", but works.

Problems with VirtualHosts

Hello I am try set up a CentOS based web server currently and am having trouble getting the domains to work.
I set up the httpd.conf as follows:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin alexgatti#msn.com
DocumentRoot /etc/httpd/www/alexandergatti.com
ServerName alexandergatti.com
</VirtualHost>
When I try to access the website the web browser says the server can't be found. I contacted my host and they said the DNS was set up corrently. Anyone have any ideas?
Did you point your domain name "alexandergatti.com" to your public ip address and do port forwarding. If you didn't point it you must point it by going to the DNS Manager zone in your domains registrant EX: Go Daddy or 1and1 and point the sites ip address to your public ip.
Next if you didn't already do this. Port Forwarding is also most important. OK so now your visitors are at your ip but your router doesn't know where to send them. So lots of routers either have them in applications and gamig or access or Virtual Server. You open it and where it says port start or public do the public port. I prefer 80 because your visitors will not have to write domain.com:8080. they just type domain.com. Ending port or private port is the ip address you set for apache. Im assuming you chose 80. So there you type 80. At the ip address or points to you type your computers private local ip which in my case is 192.168.1.205..... Click add or update or save and try your site name again. If you try it from behind your router it might not work so try it on a phone that has web in your plan or at a neighbors internet. It should work.
Also at NameVirtualHost *:80 and VirtualHost *:80 you should put your public ip instead of the star or astreics..
So it should be looking like
NameVirtualHost my.ip.add.ress:80
<VirtualHost my.ip.add.ress:80>
ServerAdmin alexgatti#msn.com
DocumentRoot /etc/httpd/www/alexandergatti.com
ServerName alexandergatti.com
</VirtualHost>