I've been playing around with trying to stand up a server that simply proxies requests to it to a different website (https://github.com) in this simple example and I just haven't been able to get it to work.
I have a simple Dockerfile
FROM ubuntu:14.04
RUN apt-get update -y && \
apt-get install -y apache2 libapache2-mod-wsgi curl
RUN a2enmod proxy
RUN a2enmod proxy_http
RUN service apache2 restart
That I'm running with docker run -it -p 80:80 --name apache proxy-test /bin/bash after building it
Once in the container, I created this file under /etc/apache2/sites-available/site1.docker.biz.conf:
<VirtualHost *:80>
ServerName test-apache.biz
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass "/github" "https://github.com"
ProxyPassReverse "/github" "https://github.com"
</VirtualHost>
Then ran:
a2ensite site1.docker.biz.conf
service apache2 reload
I want to be able to go to http://localhost:80/github and see https://github.com but I get a The requested URL /github was not found on this server.. Am I missing something?
Related
I am trying to run a PHP chat on sockets.
Server configuration: Ubuntu-18.04-amd64, Apache/2.4.29, SSL certificate from Let's Encrypt.
I use rachet. Here, here and here it is described how to connect sockets through SSL connections. But I didn’t succeed.
I installed the necessary modules in Apache:
sudo a2enmod proxy
sudo a2enmod proxy_wstunnel
sudo a2enmod proxy_http
Wrote in /etc/apache2/apache2.conf
<VirtualHost *: 443>
<Location "/chat/">
ProxyPreserveHost On
ProxyPass /ws ws://xxxxxx.xx:999
ProxyPassReverse /ws ws://xxxxxx.xx:999
</Location>
</VirtualHost>
Opened 999 port
sudo iptables -I INPUT -p tcp --dport 999 -j ACCEPT
Restarted Apache
sudo systemctl restart apache2
Launched a chat server
php /var/www/html/chat/bin/chat-server.php
Wrote in the socket call script
websocket = new WebSocket ('wss://xxxxxx.xx/chat');
I tried to connect from a browser at
https://xxxxxx.xx/chat/
And got an error
WebSocket connection to 'wss://xxxxxx.xx/chat' failed: Error during
WebSocket handshake: Unexpected response code: 301
I read various tips, but still could not understand what I was doing wrong. Any attempt to change the situation creates errors 301, 300, 500 or 200.
Please tell me what I was wrong?
How to install lets encrypt SSL in amazon Linux AMI.i want to implement the lets encrypt SSL for my domain.
There are a lot of solutions online; I think you have to keep on trying until you find one that works for you. After a lot of experimentation, what worked for me was following the certbot instructions for Apache and CentOS 6. The official link is here, but for consistency:
Run the following commands in the terminal:
Download Certbot
wget https://dl.eff.org/certbot-auto
sudo mv certbot-auto /usr/local/bin/certbot-auto
sudo chown root /usr/local/bin/certbot-auto
sudo chmod 0755 /usr/local/bin/certbot-auto
Execute Certbot
sudo /usr/local/bin/certbot-auto --apache
If there's an error message, read the warning and run (if you feel comfortable):
sudo /usr/local/bin/certbot-auto --apache --debug
Here, you may be asked to complete some fairly intuitive questions to configure your installation. If not, what worked for me won't work for you. :(
Automate Renewal
Test to see if renewing your certificate works:
sudo /usr/local/bin/certbot-auto renew --dry-run
If so, navigate to your system's crontab (usually somewhere around /etc/crontab/) and add the following code to check (and run, if necessary) and auto-renewal at midnight and noon everyday:
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && /usr/local/bin/certbot-auto renew
Here I will explain how to configure let's encrypt in Linux AMI. I did it successfully in my Linux AMI.i followed the following steps to get it done.
1. SSH into your server.
2. Download certbot (the Let’s Encrypt client need to install for renew and install ssl): **wget https://dl.eff.org/certbot-auto** then **chmod a+x certbot-auto**
3. Run certbot to fetch your certificates.follow the below code
sudo ./certbot-auto --debug -v --server https://acme-v01.api.letsencrypt.org/directory certonly -d YOUR_DOMAIN [Replace your Domain in YOUR_DOMAIN placeholde]
4. while generating it will ask you the recover or support email please add your email.
5. certbot will place your certs in the following paths…
Certificate: /etc/letsencrypt/live/YOUR_DOMAIN/cert.pem
Full Chain: /etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem
Private Key: /etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem
6. Go to your apache config where you created a virtual host it can be either in httpd.conf or conf.d.
7. Add the virtual host for 443 port
<VirtualHost *:443>
ServerAdmin ADMIN_EMAIL
ServerName YOUR_DOMAIN
ServerAlias www.YOUR_DOMAIN
DocumentRoot "YOUR FOLDER PATH"
AllowEncodedSlashes On
ErrorLog "/var/log/httpd/YOUR_DOMAIN_error.log"
CustomLog "/var/log/httpd/YOUR_DOMAIN-sslaccess.log" common
<Directory YOUR FOLDER PATH>
DirectoryIndex index.php
Options -Indexes
AllowOverride All
</Directory>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/YOUR_DOMAIN/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem
</VirtualHost>
You need to install Certbot if you are running CentOS 7 or 8 since Certbot-auto is deprecated and doesn't work beyond CentOS 6.
You can check which CentOS you are running by using the following command.
rpm -E %{rhel}
And use this tutorial from amazon to install Certbot in Amazon Linux
sudo yum update
sudo yum install -y certbot python2-certbot-apache
If you get "Package not found" error, then try the Prepare to Install section from the same blog.
sudo wget -r --no-parent -A 'epel-release-*.rpm' https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/
sudo rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-*.rpm
sudo yum-config-manager --enable epel*
I am trying to set up a customized docker container for an existing site. To do so I want to provide my own custom vhost configuration with a ServerName.
But when I try to add a custom vhost configuration and restart apache I get the warning that Apache was unable to determine the global name: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message
What's important is the fact that when I log into container's shell and manually run service apache2 restart I do not get this warning anymore.
How can I suppress that on the build? Should I provide the vhost to the composer somehow else?
Here is my docker-compose.yml is like:
version: '3'
services:
web:
build:
context: ./etc/php
args:
- APP_HOST=${APP_HOST}
ports:
- ${APP_PORT}:80
- ${APP_PORT_SSL}:443
volumes:
- ./var/bin/:/tmp/bin/
- ./app/:/var/www/html/
- ./log/:/var/log/
- ./etc/php/conf/:/usr/local/etc/php/conf.d/
environment:
- VIRTUAL_HOST=${VIRTUAL_HOST}
Then, Dockerfile that adds my own available site:
FROM php:7.0-apache
ENV TERM=xterm
LABEL maintainer="Derek P Sifford <dereksifford#gmail.com>" \
version="0.15.2-php7.0"
ARG APP_HOST
ENV APP_HOST=$APP_HOST
ADD ./sites/app.conf /etc/apache2/sites-available/app.conf
RUN sed -i 's/ServerName APP_HOST/ServerName '$APP_HOST'/g' /etc/apache2/sites-available/app.conf
RUN sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf \
&& a2enmod rewrite expires \
&& a2dissite 000-default.conf \
&& a2ensite app.conf \
&& service apache2 restart
WORKDIR /app
EXPOSE 80 443
And obviously site config:
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName APP_HOST
SetEnv APPLICATION_ENV "development"
<Directory "/var/www/html">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
As indicated here and in the warning message you can set the ServerName property to localhost in /etc/apache2/apache2.conf from within the Dockerfile.
I think there is a problem with your configuration, because you copy it and mount it on a volume. I think your configuration should not evolve when your container is live, so you don't need to mount it.
So, try to remove this line from your docker-compose.yml :
- ./etc/php/conf/:/usr/local/etc/php/conf.d/
On your apache container instance, you should put IP 172.26.0.2 in /etc/hosts and provide a fully qualified name to it e.g.
172.26.0.2 vbox.test.com
Then replace hostname with vbox.test.com
or
put localhost in serverName.
This should help you.
I'm looking to run both PHP 5.6 and 7.1 in my development server (Debian 9), with Apache. I know that Nginx can easily handle this, but I really need Apache.
Here so confs
# My main configuration file, running with PHP7.1
<VirtualHost xx.xx.xx.xx:80>
ServerName www.mydomain.com
ServerAlias mydomain.com
DocumentRoot /var/www/mydomain.com/html
</VirtualHost>
<VirtualHost xx.xx.xx.xx:80>
ServerName xx.xx.xx.xx
<Directory />
Deny from all
</Directory>
</VirtualHost>
# PHP 5.6
<VirtualHost xx.xx.xx.xx:80>
ServerName foo.mydomain.com
DocumentRoot /var/www/foo.mydomain.com/html
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock"
</FilesMatch>
</VirtualHost>
The 7.1 is working, while 5.6 returns a 404. Thanks !
If you have already installed PHP 5.6 and PHP 7.1 in your laptop and which has Apache as web server. Then use below command to run both PHP version alternatively.
Steps to run PHP 5.6 and stop PHP 7.1 :
sudo a2dismod php7.1
sudo a2enmod php5.6
sudo service apache2 restart
Steps to run PHP 7.1 and stop PHP 5.6 :
sudo a2dismod php5.6
sudo a2enmod php7.1
sudo service apache2 restart
Finally run phpinfo(); to check which version of php is running currently.
Note: To install PHP7.1 in Debian Jessie, use below link.
https://techglimpse.com/install-php-debian-jessie-linux/
Similar problem have already been asked. Go to this link. Please read everything on given link. This may help. Run multiple php version on Apache serve using fast-cgi
I've got a problem with my apache configuration.
I'm running a apache2 in a docker container.
In the same container is a webrick running on port 3000
What I want is that when someone calls subdomain.mydomain.de
There should be a pass through to
subdomain.mydomain.de:3000
I've done this:
sudo nano /etc/apache2/sites-enabled/000-default.conf
added this in default.conf
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName mydomain.de
ServerAlias *.mydomain.de
ProxyPass / http://subdomain.mydomain.de:3000/
ProxyPassReverse / http://subdomain.mydomain.de:3000/
</VirtualHost>
a2enmod proxy
sudo /etc/init.d/apache2 restart
But all what I got is this:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at [no address given] to
inform them of the time this error occurred, and the actions you
performed just before this error.
More information about this error may be available in the server error
log.
Solution for this problem is:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo service apache2 reload