Nginx + Tomcat installation

System Information
  • Strapi Version: 3.3.3
  • Operating System: Ubuntu 18 LTS
  • Database: SQLite
  • Node Version: 12.19.1
  • NPM Version: 6.14.8
  • Yarn Version:

Hi there, Strapi companions!

I have a Ubuntu install that uses Nginx as reverse proxy and Tomcat as a page/app server.

I followed this instructions

but I didn’t managed to achieve successs. I can’t access /dashboard nor /api, when I try it I get a Tomcat 404 message error.

Here’s my nginx.conf:

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
error_log /etc/nginx/logs/error.log

events {
worker_connections 1024;
}

http {
include /etc/nginx/conf-enabled/.conf;
include /etc/nginx/sites-enabled/
.conf;

# Tomcat Server
upstream rootwebapp {
    server botboutique.com.br:8080;
}

# Strapi server
upstream strapi {
    server botboutique.com.br:1337;
}

}

Here is my strapi.conf at /sites-available:

server {
# Listen HTTP
listen 80;
server_name botboutique.com.br;
# Redirect HTTP to HTTPS
return 301 https://$host$request_uri;
}

server {
# Listen HTTP
listen 443 ssl
server_name botboutique.com.br;

# SSL config
ssl_certificate /etc/letsencrypt/live/botboutique.com.br/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/botboutique.com.br/privkey.pem;

# Strapi API
location /api/ {
    rewrite ^/api/(.*)$ /$1 break;
    proxy_pass http://strapi;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_pass_request_headers on;
}

# Strapi Dashboard
location /dashboard {
    proxy_pass http://strapi/dashboard;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_pass_request_headers on;
}

}

And finally my server.js:

> module.exports = ({ env }) => ({
>       host: env('HOST', '0.0.0.0'),
>       port: env.int('PORT', 1337),
>       url: 'mydomain/api',
>       admin: {
>            url: 'mydomain/dashboard',
>            auth: {
>                 secret: env('ADMIN_JWT_SECRET', 'd1e7989csbd78ff2b56e846e8ue7yt8efd21a0'),
>            },
>       },
> });

===============================================

As I have in nginx.conf an upstream for the Tomcat root, I taked off the #Static Root directive in strapi.conf.

Any clue why it’s not working?

Thank you very much!

LuizC

Can you please use code blocks to make your message a bit easier to read?

1 Like

Sorry, @DMehaffy, now I think it’s easier.

Both of these you need the http:// or https://

@DMehaffy,

I used ‘mydomain/api’ just to escape a error message about been my first post and for that I couldn’t use more than one link :-/

In the actual file, that directives are using ‘https://mydomain.com.br

I manage to achieve some progress…

I put some of the settings in the old strapi.conf directly in 00-default-ssl.conf:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name _;

    include /etc/nginx/templates/misc.tmpl;
    include /etc/nginx/templates/ssl.tmpl;
    include /etc/nginx/templates/iredadmin.tmpl;
    include /etc/nginx/templates/roundcube.tmpl;
    include /etc/nginx/templates/sogo.tmpl;
    include /etc/nginx/templates/netdata.tmpl;
    include /etc/nginx/templates/php-catchall.tmpl;
    include /etc/nginx/templates/stub_status.tmpl;

    location / {
        root   html;
        index  index.html index.htm;
        proxy_read_timeout 120;
        proxy_pass http://rootwebapp;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    # Strapi API
    location /api/ {
        rewrite ^/api/(.*)$ /$1 break;
        proxy_pass http://strapi;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
    }

    # Strapi Dashboard
    location /dashboard/ {
        proxy_pass http://strapi/dashboard;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
    }
}

And Strapi runs flawlessly !!

Now I can reach mydomain.com/api correctly:

But when I try to access to access mydomain.com/dashboard I get a blank page. The curious thing is that is some code inside it:

<head>
    <!-- The first thing in any HTML file should be the charset --> 
    <meta charset="utf-8"> 
    <!-- Make the page mobile compatible --> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta name="mobile-web-app-capable" content="yes"> 
    <title>Strapi Admin</title> 
</head> 

<body> 
    <!-- The app hooks into this div --> 
    <div id="app"></div>
    <!-- A lot of magic happens in this file. HtmlWebpackPlugin automatically includes all assets (e.g. bundle.js, main.css)
    with the correct HTML tags, which is why they are missing in this HTML file.
    Don't add any assets here! (Check out webpackconfig.js if you want to know more)
    --> 

    <script type="text/javascript" src="[/admin/runtime~main.bcd78499.js](view-source:https://botboutique.com.br/admin/runtime~main.bcd78499.js)"></script>

    <script type="text/javascript" src="[/admin/main.dfef4c0d.chunk.js](view-source:https://botboutique.com.br/admin/main.dfef4c0d.chunk.js)"></script>

</body>

Any clue on why it’s happening?

Thanks a lot!

You never rebuilt your admin with the changes made in the server.js it looks like

Hi @DMehaffy, thanks for your support!

I used “npm run build” but the problem persists: a blank page, but the code was updated.

<script type="text/javascript" src="[/dashboard/runtime~main.5cda942b.js](view-source:https://botboutique.com.br/dashboard/runtime~main.5cda942b.js)"></script>
<script type="text/javascript" src="[/dashboard/main.f78f5b87.chunk.js](view-source:https://botboutique.com.br/dashboard/main.f78f5b87.chunk.js)"></script></body>

What’s next?

Thanks a lot!

@DMehaffy

Running in develop mode, the command line shows the address without a barr:

Is it relevant?

Can you give me your full server.js (swap the domain for something like example.com)

Right here :slight_smile:

I made a quick install in a Windows machine and saw that the barr that didin’t showed in my Linux install appears in my Windows one:

[SOLVED]

I didn’t realize why, but here’s the config files involved:

SERVER.JS (I simply reaped off “url admin” parameter)

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  url: 'https://mydomain.com.br/api',
  admin: {
    auth: {
      secret: env('ADMIN_JWT_SECRET', 'cf69c4fd38c20293191cb832da4dc641'),
    },
  },
});

NGINX.CONF (no mods)

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
error_log /etc/nginx/logs/error.log

events {
worker_connections 1024;
}

http {
include /etc/nginx/conf-enabled/.conf;
include /etc/nginx/sites-enabled/.conf;

    # Tomcat Server
    upstream rootwebapp {
        server mydomain.com.br:8080;
    }

    # Strapi server
    upstream strapi {
        server mydomain.com.br:1337;
    }

}

And in the 00-DEFAULT-SSL.CONF was a simple task of changing “dashboard” to “admin” in my “#Starpi Dashboard”

# Strapi API
location /api/ {
    rewrite ^/api/(.*)$ /$1 break;
    proxy_pass http://strapi;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
}

# Strapi Dashboard
location /admin {
    proxy_pass http://strapi/admin;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
}

Thanks for your support, @DMehaffy!!

1 Like