Hostinger VPS Deployment Question

System Information
  • Strapi Version: 3.1.0-alpha.5
  • Operating System: Ubuntu 18.04 LTS
  • Database: MySQL
  • Node Version: 10.23.0
  • NPM Version: 6.14.8
  • Yarn Version: N/A

Hello geniuses of Strapi!

Firstly, it’s so good to be here! This is my first forum post and I want to mention I absolutely love Strapi so far. I’m actually planning on using it for a big project, and that’s what brings me here!

I have a VPS with Hostinger running Ubuntu 18.04 LTS with an Apache2 web server, and I have Strapi fully installed on the server via SSH. The only problem is, when I start the server, I can’t actually access my admin panel. I have ./config/server.js set up as follows:

module.exports = ({ env }) => ({
host: env(‘HOST’, ‘api.mydomain.com’),
port: env.int(‘PORT’, 1337),
admin: {
auth: {
secret: env(‘ADMIN_JWT_SECRET’, ‘MY KEY IS HERE’),
},
},
});

And here’s a glimpse into my PuTTY terminal. I used SSH to go into the server and start Strapi as root, but even still nothing works when I visit api.mydomain.com:1337/admin.

I’ve tried setting up a reverse proxy with little success, and I feel like I need a little more guidance here. Thank you to anyone and everyone who helps out, I really appreciate it! <3

Your host needs to be bound to an actual IP interface (we use 0.0.0.0 to bind to all, unless you absolutely need to bind to a specific IP you should keep this), Thus you should never directly use a domain here, as 90% of the time the domain won’t actually resolve to that IP if you are using any kind of load balancing/ect (you mentioned big project, taking a bit of liberty in making assumptions).

Instead you need to use the url key within the ./config/server.js as laid out here: https://strapi.io/documentation/v3.x/concepts/configurations.html#server

So it should look something like:

module.exports = ({ env }) => ({
  host: env(‘HOST’, ‘0.0.0.0’),
  port: env.int(‘PORT’, 1337),
  url: env('STRAPI_URL', 'http://api.mydomain.com')
  admin: {
    auth: {
      secret: env(‘ADMIN_JWT_SECRET’, ‘MY KEY IS HERE’),
    },
  },
});

You will need to rebuild the admin if you change that url key, even if you change it via the .env file.


As for Apache, I strongly advise against using that as a proxy, while it can support it, it doesn’t handle it well. I’d suggest using Nginx or HAProxy as your proxy interface and proxy traffic over to apache if needed for some reason (if all you are doing is proxying Strapi and some static files then you don’t need apache. Nginx can even handle php if you really need it via phpfpm).

Thank you so much! I’ll give this a shot later tonight or tomorrow and let you know if it works! :smiley:

1 Like

BTW, I got it working. It was just an issue with my NGINX config. I’ve had it working for quite a while now, but I figured I’d update here too!

Glad you got it working!