Link domain to shiny server with nginx - r

I own a website bought in Godaddy and I recently created a sub-domain "tools" for this website.
My final goal is that the url: http://tools.website.com redirects to my shiny dashboard hosted on my shiny server. For that I know I need to use nginx which I did but apparently not successfully.
I am using Linux and EC2 instance, my shiny dashboard runs on http://5.82.382.227:3838/myapp/ (example). After I created the subdomain, I noticed it also runs on:
http://tools.website.com:3838/myapp/
I followed instructions and updated the shiny.conf file with the following:
server {
listen 80;
listen [::]:80;
server_name tools.website.com;
location / {
proxy_pass http://5.82.382.227:3838;
# proxy_redirect http://localhost:3838/ $scheme://$host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 20d;
proxy_buffering off;
}
}
I also figured out I had to add:
include /etc/nginx/sites-enabled/*
in the http of the nginx.conf file so I modified it by doing:
sudo nano /etc/nginx/nginx.conf
Finally, I ran:
sudo nginx -t
and get:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
and restrated nginx:
sudo systemctl restart nginx
But still does not work.

Related

Can't setup Nginx reverse proxy for Kibana in Localhost

I want to set up a reverse proxy to access kibana using a username and a password, so I followed this tutorial.
When I use the URL http://elastic.local to access kibana the timeout occurs and nothing happen.
But when I use 127.0.0.1:80 it accesses kibana without prompting any credentials.
I want to access kibana using for example http://elastic.local but can't make it work, I already googled a lot of solutions and many Nginx configuration files but none of them seems to work.
This is my configuration file named 'default' and located in etc/nginx/site-available and The symbolic link is already created and located under etc/nginx/site-enabled :
server {
listen 80;
server_name elastic.local;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users;
location / {
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
PS : I already have ELK stack in my Ubuntu vm, and it's working fine and i can access kibana using
http://127.0.0.1:5601
I managed to fix the problem what i did :
add a mapping between elastic.local and 127.0.0.1 in etc/hosts like this :
127.0.0.1 elastic.local
then restarting nginx server using :
sudo systemctl reload nginx.service

Nuxt not serving 404 but nginix is

I've just uploaded my nuxt.js site with pre-rendered HTML in universal mode, However the server is serving the 404 errors as I'm getting the server with "An error occurred" from nginix.
I'm using Docker with nginix server.
How can I get my server to let nuxt.js handle the routing and serve the errors?
Its good to use a reverse proxy before your application, here i show you my nginx nuxt configuration.
In my case the configuration is under /etc/nginx/sites-available/default.
server {
server_name homepage.com www.homepage.com;
listen 443 ssl http2;
ssl on;
ssl_certificate /etc/letsencrypt/live/homepage.at/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/homepage.at/privkey.pem;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location ~* \.(png|jpg|jpeg|ico)$ {
root /root/AutoProjekt/static;
expires 1y;
add_header Cache-Control "public, no-transform";
}
}
server {
server_name homepage.com www.homepage.com;
listen 80;
return 301 https://$host$request_uri;
}
On the top define your website name.
The port for HTTPS is 443 so you need to listen to it.
You can get the two certificates easely wih https://certbot.eff.org/ just follow the instruction.
At location you tell nginx where your nuxt projekt is in my case its at /
Important here is to pass the client to your application with is running in my case at port 3000.
The next location isnt necessary its optional. In my application i can upload images and the problem witch i have is that my images doesnt have a Cache-Control header that signals the browser to cache it. However its not essential for you here.
And the last one you listen to the port 80 witch is HTTP. There you redirect your incoming request to HTTPS.
After making changes always test for syntax errors with nginx -t and if its ok then restart your nginx with systemctl restart nginx
I also suggest to use pm2 https://www.npmjs.com/package/pm2
npm i pm2 -g
Its a production process manager that handles all your node.js processes. The problem witch you get if you just start the application with npm start is that your application stop to work if you close for examply PuTTy.
Usually you start the application with npm start but with pm2 you can start it like this:
pm2 start npm --name MyCoolApp -- start
You should see now your app with status online. To stop it type in pm2 stop MyCoolApp and for run obviously pm2 start MyCoolApp

Nginx not displaing Phoenix web app

I'm trying to deploy a basic Phoenix app to a DigitalOcean server running ubuntu 14.04. I'm using exrm to generate the release. The release works when I test it on my local machine and on the server. I'm following the Phoenix guides on deployment. The thing that doesn't seem to work is the last part with the nginx server setup. For some reason I cant get it to load anyting but the default page. When I run the
nginx -t # command. It says everything is fine.
I've tried editing the /etc/nginx/sites-available files. Doesn't seem to do anything. I've tried restarting the nginx server with
sudo service nginx reload
sudo service nginx restart
But that doesn't seem to work either.
And this is the content of my /etc/nginx/sites-available/my_app.conf
upstream my_app {
server 127.0.0.1:4000;
}
server{
listen 80;
server_name www.example.com;
location / {
try_files $uri #proxy;
}
location #proxy {
include proxy_params;
proxy_redirect off;
proxy_pass http://my_app;
# The following two headers need to be set in order
# to keep the websocket connection open. Otherwise you'll see
# HTTP 400's being returned from websocket connections.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
Update: Tried connecting directly via server_ip:port, and it worked. The url still doesnt display anything.
Solved: For some reason deleting this solves the problem.:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
Solved: For some reason deleting this solves the problem.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

How can I restart bundle nginx in gitlab separately?

I have installed Gitlab CE version. I can find nginx bundled in Gitlab. However I cannot find a way to restart nginx separately. I have tried sudo service nginx restart but it gives:
* Restarting nginx nginx [fail]
I have checked all the document but cannot find a solution. I am trying to add vhost to the bundled nginx according to this tutorial. But I stuck at that step. Is there other way to add vhost to bundled nginx with Gitlab? Or How can I check whether my nginx conf work?
Edit: 502 error I have solved.
I try to use NON-bundle nginx according to this doc , But after I modify gitlab.rb and run sudo gitlab-ctl reconfigure , I got 502 Whoops, GitLab is taking too much time to respond. error.
Here is my gitlab.conf for nginx.
upstream gitlab {
server unix://var/opt/gitlab/gitlab-git-http-server/sockets/gitlab.socket fail_timeout=0;
#
}
server {
listen *:80;
server_name blcu.tk;
server_tokens off;
root /opt/gitlab/embedded/service/gitlab-rails/public;
client_max_body_size 250m;
access_log /var/log/gitlab/nginx/gitlab_access.log;
error_log /var/log/gitlab/nginx/gitlab_error.log;
# Ensure Passenger uses the bundled Ruby version
passenger_ruby /opt/gitlab/embedded/bin/ruby;
# Correct the $PATH variable to included packaged executables
passenger_env_var PATH "/opt/gitlab/bin:/opt/gitlab/embedded/bin:/usr/local/bin:/usr/bin:/bin";
# Make sure Passenger runs as the correct user and group to
# prevent permission issues
passenger_user git;
passenger_group git;
# Enable Passenger & keep at least one instance running at all times
passenger_enabled on;
passenger_min_instances 1;
location / {
try_files $uri $uri/index.html $uri.html #gitlab;
}
location #gitlab {
# If you use https make sure you disable gzip compression
# to be safe against BREACH attack
proxy_read_timeout 300; # Some requests take more than 30 seconds.
proxy_connect_timeout 300; # Some requests take more than 30 seconds.
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://gitlab;
}
location ~ ^/(assets)/ {
root /opt/gitlab/embedded/service/gitlab-rails/public;
# gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
error_page 502 /502.html;
}
To restart only one component of GitLab Omnibus you can execute sudo gitlab-ctl restart <component>. Therefore, to restart Nginx:
sudo gitlab-ctl restart nginx
As a further note, this same concept is possible with nearly all of the gitlab-ctl commands. For example, sudo gitlab-ctl tail allows you to see all GitLab logs. Applying this concept, sudo gitlab-ctl tail nginx will tail only Nginx logs.
My tuto explains how to add vhosts to a NON-bundled nginx server, not the bundled one.
The steps are :
disable the bundled version
install a standalone nginx version compiled with passenger module,
configure it to serve gitlab as a vhost
and then configure other custom vhosts on it.
If sudo service nginx restart return
* Restarting nginx nginx [fail]
then you probably installed nginx separately with something like sudo apt-get install nginx or you installed the recompiled version with pushion passenger module as I explain in my tuto ?
Do you really use the bundled version or you misunderstood this step in my tuto ?
Please answer these questions in comments then I will edit this answer to write the solution you really need.
To restart bundled nginx do sudo gitlab-ctl restart

Installed gitlab, but only nginx welcome page shows

I installed gitlab using its installation guide. Everything was OK, but when I open localhost:80 in the browser all I see it the message Welcome to nginx!. I can't find any log file with any errors in it.
I am running Ubuntu in VirtualBox. My /etc/nginx/sites-enabled/gitlab config file reads:
# GITLAB
# Maintainer: #randx
# App Version: 3.0
upstream gitlab {
server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;
}
server {
listen 192.168.1.1:80; # e.g., listen 192.168.1.1:80;
server_name aridev-VirtualBox; # e.g., server_name source.example.com;
root /home/gitlab/gitlab/public;
# individual nginx logs for this gitlab vhost
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location / {
# serve static files from defined root folder;.
# #gitlab is a named location for the upstream fallback, see below
try_files $uri $uri/index.html $uri.html #gitlab;
}
# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location #gitlab {
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab;
}
}
The nginx documentation says:
Server names are defined using the server_name directive and determine which server block is used for a given request.
That means in your case that that you have to enter aridev-VirtualBox within your browser instead of localhost.
To get this working you have to enter aridev-VirtualBox within your local Hosts file and point it to the IP of your VirtualBox PC.
This would look something like follows:
192.168.1.1 aridev-VirtualBox
I removed /etc/nginx/sites-enabled/default to get rid of that problem.
Try following both orkoden's advice of removing the default site from /etc/nginx/sites-enabled/ but also comment out your listen line since the default implied line there should be sufficient.
Also, make sure that when you make changes to these configurations, shut down both the gitlab and nginx services and start them in the order of gitlab first, followed by nginx.
Your configuration file is right. # /etc/nginx/sites-enabled/gitlab
Maybe I think your gitlab file link is wrong.
So Example:
ln -s /etc/nginx/sites-available/default
/etc/nginx/sites-enabled/gitlab
pls check default content == your /etc/nginx/sites-enabled/gitlab
content
after
Me I changed this line :
proxy_pass http://gitlab;
by this :
proxy_pass http://localhost:3000;
3000 is the port of my unicorn server.
moreover I did a chown root:ngnix on the conf file and it work now.
Old topic, but it may happen when there is a previously installed nginx.
$ gitlab-ctl reconfigure
or restart will not complain but the previous nginx instance may actually running instead of the one under gitlab.
This just happened to me.
Shutdown and disable this old nginx instance and do again:
$ gitlab-ctl reconfigure

Resources