4

I'm try to make a deploy of one api adonis and I'm trying to use nginx to enable external access to my http requests.

I install nginx and go in ssh I go to:

cd /etc/nginx
vi nginx.conf

So, I put this code:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    server {
        listen 80;

        server_name knowhowexpressapp.com ;

        location / {
            proxy_pass http://localhost:3333;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_cache_bypass $http_upgrade;
        }
    }


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

In server name I put the domain; In port I put 3333 because is the port that I put in .env;

I start nginx:

cd /usr/bin/etc/nginx
nginx

Check if nginx is running:

[root@knowhowexpressapp etc]# ps aux | grep nginx
root      14143  0.0  0.0  55320  1028 ?        Ss   11:41   0:00 nginx: master process nginx
nginx     14144  0.0  0.0  55708  1936 ?        S    11:41   0:00 nginx: worker process
root      14188  0.0  0.0 112712   964 pts/2    S+   11:42   0:00 grep --color=auto nginx

My .env archive:

HOST=ip from my server
PORT=3333
NODE_ENV=production
APP_NAME=AdonisJs
APP_URL=http://${HOST}:${PORT}
CACHE_VIEWS=false
APP_KEY=GPhustNKtbIlrxawTZa6xQTIkHcjBXFr
DB_CONNECTION=pg
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=xxxx
DB_DATABASE=xxx
HASH_DRIVER=bcrypt

So, i check pm2 and my server is running:

⇆ PM2+ activated 
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ server    │ default     │ 4.1.0   │ fork    │ 12586    │ 16m    │ 34   │ online    │ 0%       │ 41.0mb   │ root     │ disabled │

But when i try to access my api i'm getting:

Could not get any response There was an error connecting to https://knowhowexpressapp.com/login.

My server is centos 7

My api is only running if i put the http://ipfrommyserver but when i try to access the domain i receive error.

Paulo Boaventura
  • 1,032
  • 1
  • 7
  • 25
bla
  • 667
  • 4
  • 19
  • Does this answer your question? [nginx: \[emerg\] "server" directive is not allowed here](https://stackoverflow.com/questions/41766195/nginx-emerg-server-directive-is-not-allowed-here) – EternalHour Jan 17 '20 at 21:18
  • 1
    not exacly, the adonis site this that i have to put this code that i put, if i don't put, what i have to put? https://adonisjs.com/recipes/4.1/nginx-proxy – bla Jan 17 '20 at 23:13
  • check ports `3333` and `80` are allowed in your firewall this might be the case here. – ROOT Jan 19 '20 at 17:25
  • So you access the server by IP but not by name? If this is the case you haven't pointed the A record to your server from your dns provider – C.Gochev Jan 28 '20 at 08:47
  • 1
    @C.Gochev there's a tutorial that explain how i can do this? – bla Jan 28 '20 at 13:06
  • where is your domain registered? – C.Gochev Jan 28 '20 at 13:13
  • @C.Gochev http://whois.domaintools.com/knowhowexpressapp.com this answer your question? i really never configure servers before – bla Jan 28 '20 at 13:22
  • I added this domain in a whm list accounts – bla Jan 28 '20 at 13:23
  • yes, here is a tutorial for your registrar. it's very easy https://www.enom.com/kb/kb/kb_0002_change-host-records.htm – C.Gochev Jan 28 '20 at 13:25
  • @C.Gochev there's a way to do this in WHM? – bla Jan 28 '20 at 13:51
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206799/discussion-between-c-gochev-and-veronesewiths). – C.Gochev Jan 28 '20 at 13:57
  • try `sudo tail -1000f /var/log/nginx/error.log` – Aabir Hussain Jan 30 '20 at 12:29

1 Answers1

2

Well ... I see that, as the companions said, it seems that something is missing to point the DNS to the API ... Better to use IP, it's easier ...

It has DNS propagation time ... And to accelerate ... It's good to clear your browser's cache ... Try in an anonymous browser ... Another browser ... Another PC ... And even in the case of Brazil ... Turn off the Modem ... To change the IP and update the modem's DNS.

And also CRTL + Shift + R

About login ...

When you access: http://knowhowexpressapp.com/login

 HttpException: E_ROUTE_NOT_FOUND: route not found GET / login

And when you access: http://knowhowexpressapp.com/#/login

You can see the login page ...

Even putting in https ...

By the way, see if you published SSL correctly.

To know about doors I recommend UFW, as it minimizes and updates with more practicality.

Send news!

Paulo Boaventura
  • 1,032
  • 1
  • 7
  • 25