Category Archives: amazon-ec2

Php and Flask with Apache Server with same Domain

i have an apache server (in an AWS EC2 instance) running a Landing Page written in PHP. This page is directed to let's say https// mydomain.com. Now i want to develop a Flask Application, but using the same Domain. On my research i found that i can modify my vhost.conf in this way:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
    RewriteRule ^(.*) http://%1%{REQUEST_URI} [R=301,L]
    DocumentRoot /var/www/html/xxx
Include /etc/qqq/eee.conf
SSLCertificateFile /etc/rrr/ttt/mydomain.com/yyy.pem
SSLCertificateKeyFile /etc/rrr/ttt/mydomain.com/uuu.pem


ProxyRequests off
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>
<Location /webhooks>
    ProxyPassMatch http://localhost:5000/
    ProxyPassReverse http://localhost:5000/
</Location>

</VirtualHost>
</IfModule>

This works only for the index route on my Flask Application

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
   return 'index'

@app.route('/contidions')
def condiciones():
    return render_template('conditions.html')


if __name__ == '__main__':
   app.run(debug = True)

so if i enter to mydomain.com/webhooks render 'Index', but if i try to enter to mydomain.com/webhooks/conditions, the server redirects to mydomain.com/webhooks. As you can see i'm not a server expert, so i don't know how to fix it or change it.

Thanks in advance for your help

Freshly Installed Apache-Tomcat on the AWS server, how can I access from outside world

I have installed an App with Apache tomcat on AWS ec2 instance. I am able to access the tomcat url (which is server_name:8080/BOE/BI) from the AWS instance on Win2016. Also I installed IIS on the server.

Now what are the configurations I need to do to on AWS ec2 instance to access the URL from outside the AWS instance like from my personal PC.

I also tried disabling the firewalls, it did not helped.

AWS EC2 Apache Load Balancer Issue

We have 5 t2.medium instances on AWS, all the instances connect to MariaDB via RDS on a r4.xlarge instance.

The problem is that periodically the 5 instances suddenly stop working, Apache doesn't response anymore and we can't access via SSH.

We need to reboot all instances on the AWS Console to make them work again, the Load Balancer is an application lb, the server folder "/var/www" is on a EFS to share the project.

These are the images of the monitoring, we don't know why this happen so suddenly and how can we handle it.

The last issue was this morning the 5 instances stop working and the Load balancer to.

We share the monitoring of the last 12 hours.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here Any advice?

Regards.

I am having problems installing mod_ssl onto my AWS Apache instance

I am having problems installing mod_ssl onto my AWS Apache instance...

[[email protected] ~]$ yum install mod_ssl
Loaded plugins: priorities, update-motd, upgrade-helper
You need to be root to perform this command.
[[email protected] ~]$ sudo yum install mod_ssl
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
--> Running transaction check
---> Package mod_ssl.x86_64 1:2.2.34-1.16.amzn1 will be installed
--> Processing Dependency: httpd-mmn = 20051115 for package: 1:mod_ssl-2.2.34-1.16.amzn1.x86_64
--> Processing Dependency: httpd = 2.2.34-1.16.amzn1 for package: 1:mod_ssl-2.2.34-1.16.amzn1.x86_64
--> Running transaction check
---> Package httpd.x86_64 0:2.2.34-1.16.amzn1 will be installed
--> Processing Dependency: httpd-tools = 2.2.34-1.16.amzn1 for package: httpd-2.2.34-1.16.amzn1.x86_64
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.34-1.16.amzn1.x86_64
--> Running transaction check
---> Package apr-util-ldap.x86_64 0:1.5.4-6.18.amzn1 will be installed
---> Package httpd-tools.x86_64 0:2.2.34-1.16.amzn1 will be installed
--> Processing Conflict: httpd24-2.4.33-2.78.amzn1.x86_64 conflicts httpd < 2.4.33
--> Processing Conflict: httpd24-tools-2.4.33-2.78.amzn1.x86_64 conflicts httpd-tools < 2.4.33
--> Finished Dependency Resolution
Error: httpd24-tools conflicts with httpd-tools-2.2.34-1.16.amzn1.x86_64
Error: httpd24 conflicts with httpd-2.2.34-1.16.amzn1.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
[[email protected] ~]$

I have tried running sudo yum install 24mod_ssl to no avail? It says No package 24mod_ssl available.

What can I do?

Terminated the ‘mysqld’ process in Amazon Linux – everything appears to work, or does it?

So I noticed that the 'mysqld' process on my Amazon Linux machine (EC2 Instance) was hogging a ton of memory. I terminated it and it instantly resolved this issue. I have separate RDS databases and I can still access and transmit information to these over the web via my host with no issues whatsoever. I assume other processes help handle this.

So my question is: Although everything appears to work on the front end web pages, what's the downside to not having this process running? I noticed that there are other databases labeled "information_schema" and "mysql" that have data being written which are modified very frequently, but I didn't create these DBs and they aren't application critical.

So is this process just storing server information into those DBs? Will having this off cause more chaos than it's worth?

EDIT: I've discovered that the information being stored into the databases is all coming from functions in the RDS service, NOT the linux host. So the assumption still stands that if I am not running queries into 'localhost' then I don't need this process at all. I only directly communicate with Amazon RDS.

How do I hide IP address on EC2 hosted site multiple sites hosted

I have hosted 2 websites on my ec2 via virtual host, so the path is something like

/var/www/html/cars.com /var/www/html/bikes.com

now the cars.com works fine all urls open with http://cars.com/1.html http://cars.com/2232.html

but in the bikes.com the urls are opening as http://172.165.145.15/bikes.com/1.html

so how do I hide the ip address and folder path in this case

thanks

Websocket connection error Actioncable rails5 apache aws

Action cable not working in AWS with ssl. Getting the following error. It's working fine in local environment.

WebSocket connection to 'wss://www.example.net/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

Here's my apache configuration.

<VirtualHost *:80>
ServerName    example.net
DocumentRoot /home/ubuntu/mydomain/public
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
<Proxy balancer://unicornservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
<Proxy balancer://thinservers>
Allow from any
BalancerMember http://127.0.0.1:9292
</Proxy>
ProxyPass /faye http://127.0.0.1:9292
ProxyPassReverse /faye http://127.0.0.1:9292
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/home/ubuntu/mydomain/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName    example.net
DocumentRoot /home/ubuntu/mydomainco/public
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
RequestHeader set X-Forwarded-Proto "https"
RewriteCond %{HTTP_HOST} ^mydomain/.net$ [NC]
RewriteRule ^ https://www.example.net%{REQUEST_URI} [R=301,L]
<Proxy balancer://unicornservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
<Proxy balancer://thinservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule "/cable" ws://127.0.0.1:3000/cable [P]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/ubuntu/ssl/31755a8ebd042758.crt
SSLCertificateKeyFile /home/ubuntu/ssl/mydomain.key
SSLCertificateChainFile /home/ubuntu/ssl/gd_bundle-g2-g1.crt
<Directory "/home/ubuntu/mydomainco/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>    

Websocket connection error Actioncable rails5 apache aws

Action cable not working in AWS with ssl. Getting the following error. It's working fine in local environment.

WebSocket connection to 'wss://www.example.net/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

Here's my apache configuration.

<VirtualHost *:80>
ServerName    example.net
DocumentRoot /home/ubuntu/mydomain/public
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
<Proxy balancer://unicornservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
<Proxy balancer://thinservers>
Allow from any
BalancerMember http://127.0.0.1:9292
</Proxy>
ProxyPass /faye http://127.0.0.1:9292
ProxyPassReverse /faye http://127.0.0.1:9292
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/home/ubuntu/mydomain/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName    example.net
DocumentRoot /home/ubuntu/mydomainco/public
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
RequestHeader set X-Forwarded-Proto "https"
RewriteCond %{HTTP_HOST} ^mydomain/.net$ [NC]
RewriteRule ^ https://www.example.net%{REQUEST_URI} [R=301,L]
<Proxy balancer://unicornservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
<Proxy balancer://thinservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule "/cable" ws://127.0.0.1:3000/cable [P]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/ubuntu/ssl/31755a8ebd042758.crt
SSLCertificateKeyFile /home/ubuntu/ssl/mydomain.key
SSLCertificateChainFile /home/ubuntu/ssl/gd_bundle-g2-g1.crt
<Directory "/home/ubuntu/mydomainco/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>