I have a website setup http://mydomain.com/myroject
on ubuntu 14.04(apache webserver)
I setup htsql service on the same host to run on port 5000
working links:
http://mydomain.com/myproject
http://mydomain.com:5000/region
Then I installed ssl cert on this server to run the website through https
https://mydomain.com/myproject
is working but https://mydomain.com:5000/region
is not working because the port 5000 is already in use where htsql service is running on this port
Now the question is how do I redirect on the same port(5000) from http to https with nginx reverse proxy
In other words https://mydomain.com:5000/region
should work
My idea is to setup a different port(eg: 5001) on nginx and forward the request to https, 5000 port.
Here are apache configuration files:
/etc/apache2/ports.conf
Listen 80
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
/etc/apache2/sites-enabled/default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName mydomain.com
SSLEngine on
SSLCertificateFile /home/ubuntu/project.crt
SSLCertificateKeyFile /home/ubuntu/project.key
</VirtualHost>
nginx configuration file:
default.conf
server {
listen 5001 ssl;
server_name my domain.com;
ssl on;
ssl_certificate /home/ubuntu/project.crt;
ssl_certificate_key /home/ubuntu/project.key;
error_page 497 301 =307 https://mydomain.com:5001$request_uri;
location / {
proxy_pass https://mydomain:5000;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl on;
}
}
http(s)://mydomain.com/myproject
. The database is running onhttp://mydomain.com:5000/region
. Correct me if I'm wrong. If you want an external connection to the database, you could usehttp(s)://mydomain.com/region
(on port 80 and 443) and proxy the requests tohttp://mydomain.com:5000/region
(internally) and close port 5000 in the firewall. No need for nginx. No need for an extra port 5001. See the mod_proxy Reverse Proxy example.