Access Local Domain Name Website as API server in WAMP - wamp

I have two local Domain which work fine, however, the otherA domain is the API server that the otherB domain consumes API. The problem is it can't access the otherA domain, and returns network error something like
option 1
let apiserver = 'http://localserverA.local'
axios.get(`${apiserver}/apicall`).....
catch( ---> return network error
But this works
option 2
let apiserver = 'http://127.0.0.1:8000'
axios.get(`${apiserver}/apicall`).....
returns 200 ok
The problem with option 2 is to run php built in server which not a good idea because some set up in databases requires domain local host to access its data.
<VirtualHost *:80>
ServerName localserverA.local
ServerAlias localserverA.local
DocumentRoot C:/projects/r/projects/A/web
<Directory "C:/projects/r/projects/A/web">
AllowOverride All
Require all granted
Allow from All
Allow from 127.0.0.1
Allow from ::1
#FallbackResource /app.php
</Directory>
</VirtualHost>
I can even ping my domain name, it works well in browser but got network error when endpoint called via javascript. Works well in production
Any Idea?

This may help you:
Go to directory (from where your landing page load, if you have laravel project you need to go to public directory) to your project in command promt and fire command.
php -S <ip addresss>: <any port no>
like this
php -S 192.168.1.62:4200
Now you can access that project using 192.168.1.62:4200

You need to change your %SystemRoot%\system32\drivers\etc\hosts file. Add next line:
127.0.0.1 localserverA.local

Related

How to setup port to subdomain in AWS?

I have a domain (e.g. example.com) registered with godaddy.com and use AWS for hosting.
Nameserver on Godaddy later added to AWS
I have an ubuntu (t2.medium) apache server installed. My project in Docker has LAMP, ELK, Node, React, and Postgres installed. Everything works on the local system using direct ports. Few ports open in my project i.e.
example.com:3000 react app [frontend]
example.com:5601 kibana app
example.com:5050 postgradmin app
example.com/radius php applicatinn [backend]
example.com:8080 phpmyadmin app
my desired URLs are:
example.com:3000 react app [frontend] => http://example.com
example.com:5601 kibana app => http://kibana.example.com
example.com:5050 postgradmin app => http://postgradmin.example.com
example.com/radius php applicatinn [backend] => http://example.com/radius
example.com:8080 phpmyadmin app => http://phpmyadmin.example.com
I have tried a few things but nothing is working. on route53
tried reverse proxy on apache by adding separate conf files e.g.
default.conf
<VirtualHost *:80>
ServerAdmin contact#example.com
DocumentRoot "/var/www/html"
ServerName example.com
<Directory "/var/www/html/">
AllowOverride all
</Directory>
</VirtualHost>
kibana.conf
Listen 5601
<VirtualHost *:5601>
ServerAdmin contact#example.com
ServerName kibana.example.com
</VirtualHost>
pgadmin.conf
Listen 5050
<VirtualHost *:5050>
ServerAdmin contact#example.com
ServerName pgadmin.example.com
</VirtualHost>
when I run docker-compose up on EC2, http://example.com/radius works fine. but others do not (e.g. http://kibana.example.com). but if try with port directly (e.g. example.com:5601) it's working. but I want to use a sub-domain not a domain with a port.
How to do that?
reverse proxy I tried as mentioned in the description but it's not working properly
First, if you want your domains to be publicly accessible. You need to create records for all domains.
Second, if you want to access by only domains without port, you should create multiple blocks of virtual host listening to only port 80, and then do the routing base on domains your server received
Example can be found here

Apache throws ERROR 500: Internal Server Error when GET from localhost/internal network

I have a production server with apache and django installed using mod_wsgi.
The django application has a REST API that serves some info when a GET request is sent.
This has always worked fine on the develop server, were we ran django using manage.py in a screen. Now we created a production server with apache running django but this API returns Error 500 when running wget from localhost or other machines in the same network (using 192.168.X.X IP).
Here's the output from wget:
~$ wget localhost:80/someinfo
--2020-04-02 16:26:59-- http://localhost/someinfo
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2020-04-02 16:26:59 ERROR 500: Internal Server Error.
It seems that the connection succeeds, so I guess it's not an apache problem. The error comes from the API response.
The error in apache error.log looks like this:
127.0.0.1 - - [02/Apr/2020:14:24:36 +0000] "GET /someinfo HTTP/1.1" 500 799 "-" "Wget/1.19.4 (linux-gnu)"
question: what is the number after 500? Sometimes is 799 and other times is 803.
But if the request is done using the public IP of the server from outside (i.e. from the browser) the API works fine and I see the correct information.
I already checked django's allowed hosts and it was accepting localhost, and the 192.168.X.X IP of the other machine. In the end I left django's settings.py like this:
#ALLOWED_HOSTS = ['localhost', '127.0.0.1', '192.168.1.101']
ALLOWED_HOSTS = ['*']
Note: 192.168.1.101 is the machine that tries to make the GET request.
The final goal of all this is to be able to make a GET request from a python script running in that machine (which already works if django runs via manage.py).
My apache.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
#DocumentRoot /var/www/html
Alias /static /home/myuser/myproject/django/static_root
<Directory /home/myuser/myproject/django/static_root>
Require all granted
</Directory>
<Directory /home/myuser/myproject/django/myproject_django>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-home=/home/myuser/env python-path=/home/myuser/myproject/django
WSGIProcessGroup myproject
WSGIScriptAlias / /home/myuser/myproject/django/myproject_django/wsgi.py
</VirtualHost>
I tried running django via manage.py and the wget from localhost works just fine. The problem only appears when django is ran by apache.
I also tried the solution given in this post, but changing the line does not fix the error.
I have some doubts concerning this error:
how does apache run django?
does restarting apache2 service also restart django? (thus, reading again the settings.py)
Is there any other django settings file rather than the one I'm editing?
how can I see django logs? I don't have the console now so I can't see real time prints.
I appreciate a lot any help.
I finally managed to solve it myself.
It turns out wsgi handles requests from localhost or external IPs as different instance groups. So all I had to do is put
WSGIApplicationGroup %{GLOBAL}
in /etc/apache2/sites-available/000-default.conf

Route a specific path to a specific EC2 instance using Route 53

I'm not sure if this is even possible, but if so I'm looking for the best way to do it.
Say I want to host my blog for example.com on it's own EC2 instance, and I want the path to my blog to be example.com/blog
Is it possible to route all requests to example.com/blog/* to one instance, and all other requests to that domain elsewhere?
My web server is Apache.
Thanks!
You can now do this with Application Load Balancer and path-based routing: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/tutorial-application-load-balancer-cli.html#path-based-routing-aws-cli
Certainly it's possible, but not with DNS nor with an ELB. The most common solution to this is to use a web server that issues a 301 or 302 redirect.
In your case, example.com would point to whatever the main site is. The web server (nginx or Apache httpd, perhaps) hosting example.com would have a redirect for example.com/blog/* that is found at another destination.
Here's an SO post on using Nginx for a redirect and for using Apache for a redirect.
Yes, but you would have to proxy your requests through an instance handling example.com. How you configure this depends on your web server.
Some examples on how to configure this:
nginx: http://wiki.nginx.org/HttpProxyModule
Apache: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
Since you are using Apache2 Server, so you can achieve this very easily by creating a Virtual Host.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/vchost1.com.conf
Create Virtual Configuration using the above command, it copies the complete code of content from the default file provided by the apache2 Server.
sudo nano /etc/apache2/sites-available/vchost1.com.conf
start configuring host & domain according to your requirements
<VirtualHost *:80>
ServerAdmin admin#domain.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
here also, you can multiple Virtual Host configurations in a single file, start configuring and enjoy hacking.
you can also multiple web applications in a single instance by using the same method and theis reference.
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04-quickstart

HOw can i use subdomain with django and mod_wsgi

I have my main site at www.example.com
I want to run sites like site1.example.com
I tried this
<VirtualHost ip:80>
DocumentRoot /home/user/django/app
ServerAlias site1.example.com
I have also added record to /etc/hosts but its not working.
i am able to ping site1.example.com from server but not from outside
i am able to ping site1.example.com from server but not from outside
This is not a Django problem. ping is a low-level IP protocol (ICMP) that is handled well down from the HTTP server (application) level.
Adding something to /etc/hosts only affects the machine that /etc/hosts is on.
You should get subdomains working with static web pages (e.g. "Hello World") first, leaving Django out of it. Then read up on django.contrib.sites and go from there.

How to configure Apache httpd to set multi-site for multi-user?

I have a system CentOS with Django and MySQL.
/home/user1/
-/vhost/*.conf
-/webapps/
abc.com
xyz.com
/home/user2/
-/vhost/*.conf
-/webapps/
123.com
789.com
Thanks for help!
UPDATE 1:
In httpd.conf:
User user1
Group apache
And httpd cannot access /home/user2/webapps.
You'll want to read up on Apache Vhost Configuration.
Tell us what you tried, what is working, what is not working, or what you don't understand.
Most common configuration
If your system has 1 IP address for all sites, you're going to want something like this:
#This is your 'default' host,
#people accessing the site via IP-address will see this site.
<VirtualHost *:80>
ServerName abc.com
ServerAlias xyz.com
DocumentRoot /home/user1/webapps/
</VirtualHost>
#This is the 123 and 789 vhost
<VirtualHost *:80>
ServerName 123.com
ServerAlias 789.com
DocumentRoot /home/user2/webapps/
</VirtualHost>
You can add all directives as explained by the <VirtualHost> Directive
EDIT: Updated question
There is a module called
perchild for apache that allows
to run different threads under
different users, configurable by
vhost. The module is not considered
functional, and not under current
development. Unless you know what
you're doing or are willing to take
the risk, you probably shouldn't use
it.
Another solution might be mpm-itk,
which appears to be more reliable.
Read this serverfault question
for more information, or visit their
homepage.
If you don't want to use either of both modules, you could always create a new user and group, run both vhosts under that user, and make both homedirs readable to the user by setting their group to the new group.