Domain name or webservice not working - php

I apologize for the bad formatting.
i am stuck at a point regarding the domain name or webservice.
when we call the webservice on the local server it is working but when we call the service from some remote location it is giving "404 not found error".
Thanks in advance

I agree with Night2, this sounds like it could only be a VirtualHost situation.
In short, if you can ping the server with a domain name from another machine then dns-wise you're fine as the name resolves correctly. Getting a 404 means you are hitting your web server - apache or whatever you're using as that's an HTTP error, it doesn't sound like a port problem. If it works locally and you're using the same name from another machine it's not a ServerAlias problem.
The syntax for setting up the VirtualHost (in apache) you can get from here.
In short what that means it that you have something that looks like this:
<VirtualHost 10.1.2.3:80>
The IP means that's what IP and port that VirtualHost is listening on. If you have only an internal IP there then you'll only be able to hit it interally and you'd have to use *:80 or specify IP as is applicable so apache will track with which VirtualHost to route the request to.

Related

curl return 404 error on any file in the server, suspecting it is trying to load another directory

I have a client and I need to execute a curl script on it's server but I get a 404 error.
First I tried the other suggestions I've found on other solutions here (adding headers, cookies...)
After that I asked for a SSH access to be able to check more and that's what I've found:
The only URL that doesn't returns a 404 is the home http://aksentropis.com and it doesn't return the homepage's content it just return
<html><body><h1>It works!</h1></body></html>
So I've decided to investigate where this text could be and I've found it on another completely different directories using grep:
./usr/src/httpd-2.4.23/docs/docroot/index.html:1
./usr/local/apps/apache2/www/htdocs/index.html:1
I've entered those directories and they only contain the index.html file
But, the main folder for public_html is on:
/home/admin/public_html
How can I fix that, or what should I do? I only have a ssh root access.
Update: if I call the url from another server it just works...
Update: I've found the DocumentRoot in the apache was misconfigured.
It was pointing to
DocumentRoot "/usr/local/apps/apache2/www/htdocs"
and I've updated it to
DocumentRoot "/home/admin/www"
Now it loads the php but it doesn't execute it. Why is that?
It looks to me like the vhost for this site isn't configured to accept your requests. This could either mean from your location, or using the port you're using.
It could be a matter of your source location. A Require, Allow from or Deny from directive inside your vhost can manage access control.
Apache Docs: Access Control
Perhaps a proxy (such as a load balancer or firewall) usually intercepts port 443 and 80 traffic and redirects it to other ports, and your vhosts are configured to listen to those other ports. Right now all traffic (from your curl location, most likely localhost) appears to be directed to the default apache site, and paths relative to that index file.
Please check the virtual host configuration for this site. It can usually be found in /etc/apache2/sites-enabled/. If the VirtualHost block for that site contains a colon followed by a number, then that's the port number this block is applied to:
<VirtualHost aksentropis.com:1234>
DocumentRoot "/home/admin/public_html"
</VirtualHost>
In the above example the server would be configured to listen to port 1234, which means there's usually something that's between external traffic and the server. Apache Docs: Binding to Addresses and Ports

How to handle incoming CNAME records and point to the specified URL?

I have looked everywhere for something on this but can't seem to find anything.
After setting up the CNAME record of a domain (i.e. user_domain.com) to point to my own example.com, what would be the next step? How would I get it to point to example.com?
I believe that I will need to do something on my end in order to handle these domains but I can't find any tutorials on how to do so.
The error that is received when visiting user_domain.com is:
user_domain.com’s server DNS address could not be found.
For the record, I am using Ubuntu, Apache and PHP. Would something need to be done to the .htaccess file?
CNAME
www example.com
Overall
I am trying to let users point their own domain to example.com
What would be the next step after setting up the CNAME record?
I would appreciate any help, thanks!
You either have to:
Configure your Apache with name-based virtual hosts and have it listen explicitly for the new domain via the ServerAlias directive.
Or:
Configure your Apache for IP-based hosts. It will serve the example.com content for whatever domain name is pointed at it.
Or:
Configure your Apache with name-based virtual hosts and have it listen implicitly for the new domain by making sure example.com is the first vhost listed in the config. This will make example.com the "default" service for IP-based requests. (Not 100% sure about this one, but this is how I recall Apache behaving.)

DNS with subdomain doesn't work properly

I have a domain name with OVH but i am hosted on a shared server elsewhere (not very important).
I configured my DNS zones on OVH panel to make my domain name pointing on my server.
.pari-esc.fr A 188.165.201.172
www.pari-esc.fr A 188.165.201.172
redmine.pari-esc.fr A 188.165.201.172
pari-esc.fr and www.pari-escfr are working fine but redmine.pari-esc.fr isn't.
On my shared server admin panel, i configured my subdomain :
Host : redmine
Domain : pari-esc.fr
Redirection Type : L
Path : /redmine/
But when i am trying to access to redmine.pari-esc.fr i have an error :
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator....
More information about this error may be available in the server error
log.
Additionally, a 500 Internal Server Error error was encountered while
trying to use an ErrorDocument to handle the request.
The weird part is when i am trying to access to redmine.pari-esc.fr/index.html, its working... so i am a bit lost...
I thought redmine.pari-esc.fr would automatically find index.html and i don't understand why he is not..
I tried to put a .htaccess with a DirectoryIndex index.html but it didn't resolve my problem...
Maybe there is an other way to configure DNS or subdomain and i did it bad ?
So my purpose is : when i am going to redmine.pari-esc.fr i want to display my index.html located in my /redmine/ directory
Thank you in advance for your help !
The DNS settings are looking ok. Check your path in the server config. /sub/ is an absolute path and that is quite likely not correct. It should be something like /var/www/(your web directory)/sub if it's absolute or simply ../sub/ or sub/ if its relative.

Can I get the virtual directory (if there is one) with the $_SERVER variable?

I want to be able to have one way of creating dynamic URL's that works in development and production. Right now I'm building the URL's like this:
header("Location: http://".$_SERVER["HTTP_HOST"]."/contact.php?failed");
but the problem with this is that I currently run the site like this off my WAMP server:
http://localhost/vdname/contact.php
and so that line of code doesn't generate the right URL in development - it builds:
http://localhost/contact.php?failed
instead and thus I get an expected 404. How can I build the URL's properly so that they work in both development and production?
EDIT
Per a number of suggestions, it would better to leverage VirtualHost entries in the httpd.conf file for this so I could use a normal domain name locally. So, I'm trying to get that to work and it's not working like I want, consider this code from the conf:
#Listen 12.34.56.78:80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example
ServerName local.example.com
</VirtualHost>
and the associated hosts file configuration:
127.0.0.1 local.example.com
but when I navigate to http://local.example.com/contact.php I get a 403 Forbidden and when I run an nslookup local.example.com I don't get 127.0.0.1 either.
For my stuff I use $_SERVER['SERVER_NAME'] instead of $_SERVER['HTTP_HOST']. Because the HTTP_HOST is pulled from the HTTP request header and it is client set. If someone hits your site from www.yoursite.com and yoursite.com you might actually have two different results for HTTP_HOST in the same session. This can play havoc with cookies and redirects, not to mention with your site in terms of SEO and traffic patterns.
To stay on the same site, rather than populating the header() location command with an offsite URL (containing HTTP), you can use this instead:
header("Location: /contact.php?failed");
Also in your form you can use this:
<form action="/gdform.php" method="post" style="float: left;">
By using that style of links the browser will stay on the same site without performing a look-up (DNS) and it will stay in the same SubDNS.
You would need to make sure that $_SERVER['SERVER_NAME'] was properly configured in Apache, assuming that's what you're running.

PHP get_headers not working on local Apache URLs

I'm using get_headers() to see if sites are up or not, and it's all fine, but when I try and check my local sites, I get a 'response timed out' error. The 'local' URLs are not on a 'real' domain, but are something like:
http://steve-emachine/WEBSITES_PHP/Sites/HOGSMILL/index.php
...where 'steve-emachine' is my machine name. Is there any way to use get_headers() on this kind of URL? The URLs work fine in a browser, so it's obviously just my ignorance of how HTTP works that is the problem.
Though for me, the url formats you mentioned is working, make sure that you have entry in hosts file of your operating system for that particular domain which you are using (steve-emachine in your case).
To use get_headers() on local site, you can do this:
Add virtual-host on your server, with some name like local.mysite.com
Make host entry in your operating system for that domain
127.0.0.1 local.mysite.com
Restart your server
use $url = http://local.mysite.com in get_headers(), it will work fine.
Make sure you use the full address with the http:// prefixed to it in your php code. Like this
http://local.mysite.com
the hosts file is in /etc/hosts on linux and looks something like
127.0.0.1 localhost
127.0.1.1 drew-ThinkPad-T410
127.0.0.1 local.mysite.com

Categories