nginx enables https on port 80 and 8080 only - nginx

I know almost nothing about nginx, please help me to see if it can be achieved ?
A public network IP with only 80 and 8080 ports open, Such as 182.148.???.135
A domain name with an SSL certificate, Such as mini.????.com
This domain name can resolve to this IP.
Using the above conditions, how to enable https ? So that I can pass visit https://mini.????.com to the target server 182.148.???.135
Thank you very much for your help!

Just came accross an issue. Doesn’t matter if its a local setup or one with a domain name.
When you create a symbolic frpom sites-available to sites-enabled you have to use the whole path to each location.
e.g. you can’t
cd /etc/nginx/sites-available/
ln -s monitor ../sites-enabled/
It has to be:
ln -s /etc/nginx/sites-available/monitor /etc/nginx/sites-enabled/
Inside /etc/nginx/sites-available you should have just edited the default file to change the root web folder you specified and left the server name part alone. Restart nginx, should work fine. You don’t need to specify the IP of your droplet. That’s the whole purpose of the default file.
You only need to copy the default file and change server names when you want to set up virtual hosts.

Related

Why does changing the fully qualified domain name in /etc/hosts not update the fully qualified domain name?

I am running Ubuntu 18.04 in a VM. When I check the hostname using hostname or the fully qualified domain name using hostname -f, hostname --fqdn or hostnamectl I get the default ubuntu for each. I want to permanently update the hostname to host and the fully qualified domain name to host.okd.dns.
I have changed the file /etc/hostname to include only the name host. I have also changed the file /etc/hosts to appear as follows (excluding IPv6 hosts):
127.0.0.1 localhost
127.0.1.1 host.okd.dns
After saving and rebooting the VM, when I check hostname it returns host as expected, but when I check the FQDN using hostname -f, hostname --fqdn or hostnamectl it also returns host only without the .okd.dns appended to it as I would expect.
There seem to be several methods of updating the FQDN for Ubuntu 18.04 and I have tried most of them, including this method, which seems to be the most common. What do I need to do to get the changes to the FQDN to update and stick?
Apparently, I needed to add host after host.okd.dns in the /etc/hosts file. I was sure I had tried this in the past, but perhaps there was some other error I had made somewhere and this wasn't reflected. Once doing this and after a reboot, hostname -f and hostname --fqdn both return host.okd.dns as expected.

How can I tell if a docker container is on localhost or 192.168.99.100

Is it possible in docker-compose or through some environment variable to figure out the hostname that docker is linking to containers? The wordpress home and siteurl are set to localhost:8000 which work fine on docker for mac, but when used on docker toolbox for windows, the site is hosted on 192.168.99.100:8000, which then redirects back to localhost and fails. Is it possible to determine whether the host is localhost or 192.168.99.100 in docker-compose?
I wound up putting together a simple bash script in the root folder that asked for input on what host the user wanted to use (localhost vs 192.168.99.100) and piped the answer to a .env file (https://docs.docker.com/compose/env-file/#syntax-rules). I then passed that environment variable to the relevant containers in docker-compose.yml. Maybe not the most elegant solution, but it worked in a pinch.

gitlab repository URL unchanged after reverse proxy changes

I am using a nginx reverse proxy to serve gitlab web app on port 80. ie nginx reverse proxy will redirect queries to http://ip-address/gitlab to http://ip-address:8000/gitlab . I have updated 'external_url' in my 'gitlab.rb' file. Everything is working (ie I am able to access the gitlab web-intrface via http://ip-address/gitlab ), except the generated git clone URLs. When I create new git projects, the repo URL is shown as http://ip-addeess:8000/gitlab/user/testproject.git. ie the port is still there. How can I remove the port?
The displayed repository URL is generated from the parameter external_url in your gitlab.rb file.
You should set it like this:
external_url 'http://ip-address/gitlab'
Then run sudo gitlab-ctl reconfigure to apply this change.
Add "proxy_set_header Host $http_host;" in your "location / { directive.
Then restart nginx.
It should resolve your issue

Let's encrypt 502 bad gateway docker

I tried to set an nginx proxy with let's encrypt, all dockerized, by following this tutorial :
http://www.automationlogic.com/using-lets-encrypt-and-docker-for-automatic-ssl/
The problem is that my application exposes port 1337 instead of 80, and I can't change this for now.
Do someone know how I could tell nginx to listen on the app container's at 1337?
After looking at that tutorial and the available source code, the nginx configuration files are using a placeholder _APPLICATION_PORT_ which gets replaced with the nginx docker container's environment variable $APP_PORT_80_TCP_PORT in it's start.sh script. It appears that specific environment variable would need to be added to the docker-compose.yml file:
nginx:
environment:
- APP_PORT_80_TCP_PORT=1337
You would also need to make sure that the docker-compose.yml has the correct port for your application (if docker-compose is launching your application container) so docker exposes the correct port.
Hope that helps

Tunnel a localhost subdirectory through ngrok?

Objective: want to share a website preview using ngrok, which creates a tunnel from which my localhost can be seen with an url of something like mywebsite.ngrok.io
Problem: I use WAMP and my localhost folder looks something like this:
localhostdirectory
|-- website1
|-- website2
|-- etc
To access a website I type to localhost/website1/ in the browser, I would like to tunnel only that URL, the possible solutions would be:
Setting up a Virtual host, I would go through the hassle of manually setting up a virtual host, then I get something like website1.dev, and then I would pass it to ngrok as the host header in the HTTP request, like that:
ngrok http -host-header=website1.dev 80
I didn't understand what the host header is though, and why can't I pass a relative url like localhost/website1/, also what is the rewrite option?
Change the folder directory of my localhost to the folder of the website, I would prefer not to do that.
Is there a better way to accomplish my objective in an easier way, maybe going through WAMP aliases?
If you make do with Apache Vhost you just have to exec command
ngrok http -host-header=rewrite YOUR-LOCAL-DOMAIN:PORT
Dont forgot to edit host file for resolution #IP <-> YOUR-LOCAL-DOMAIN
I tried below way.
When I ran $ ./ngrok http 80 ngrok listen to localhost:80 which shows dashboard because apache server is running on port 80. Then I tried running subfolder in another port, which solved problem. Assume you have project in xyz and want ngrok should points it. Then do following
$ cd /opt/lampp/htdocs/xyz
$ php -S localhost:8080
Here 8080 is any unused port. localhost:8080 direct points to xyz and then open other terminal
$ ./ngrok http 8080
By doing this ngrok will listen to 8080 port were your xyz is running.
Hope this helps!!
After you set up the ngrok address to point to localhost on port 80, you can access your websites by their names.
Ex:
ngrok http -subdomain=dev 80
Access website1:
dev.ngrok.io/website1
I believe the correct syntax now for ngrok v3 is ngrok http --host-header=rewrite YOUR-LOCAL-DOMAIN:PORT
Notice the double --
https://ngrok.com/docs/guides/upgrade-v2-v3

Resources