Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 message every route after creating the project #1088

Closed
1 task done
matschik opened this issue May 2, 2018 · 10 comments
Closed
1 task done

404 message every route after creating the project #1088

matschik opened this issue May 2, 2018 · 10 comments
Assignees
Labels
issue: feature request Issue suggesting a new feature

Comments

@matschik
Copy link

matschik commented May 2, 2018

Informations

  • Node.js version: 9.11.1
  • npm version: 5.6.0
  • Strapi version: 3.0.0-alpha.12.0.1
  • Database: MongoDB 3.6
  • Operating system: Debian 8 (64 bits)

What is the current behavior?
I get a 404 message when I'm going to mydomain.com/strapi.
I redirect mydomain.com/strapi to port 1337 with Nginx.

mydomain.com/strapi

{"statusCode":404,"error":"Not Found","message":"Not Found"}

PM2 logs

2|strapi   | [2018-05-02T14:21:03.990Z] debug Launched in: 1638 ms
2|strapi   | [2018-05-02T14:21:03.990Z] debug Environment: development
2|strapi   | [2018-05-02T14:21:03.990Z] debug Process PID: 11790
2|strapi   | [2018-05-02T14:21:03.991Z] debug Version: 3.0.0-alpha.12.0.1 (node v9.11.1)
2|strapi   | [2018-05-02T14:21:03.991Z] info To shut down your server, press <CTRL> + C at any time
2|strapi   | [2018-05-02T14:21:04.768Z] debug GET /strapi (47 ms)
2|strapi   | [2018-05-02T14:21:04.944Z] debug GET /strapi/admin (2 ms)

Nginx config

 location /strapi {
        proxy_pass http://localhost:1337;
        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;
    }

Steps to reproduce the problem
After creating the project with strapi new myProject, I launch the server pm2 start server.js -n strapi. Go to mydomain.com/strapi after configuring nginx redirection and restarted Nginx.

What is the expected behavior?
I must see strapi app.

  • I'm sure that this issue hasn't already been referenced
@matschik
Copy link
Author

matschik commented May 3, 2018

I changed Nginx config to:

 location / {
        proxy_pass http://localhost:1337;
        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;
    }

It worked ! I must load Strapi only on server root. That's why all /strapi/* routes return 404.

Possible fix
Strapi must support other than root server url /.

@lauriejim lauriejim added the issue: feature request Issue suggesting a new feature label May 3, 2018
@Aurelsicoko
Copy link
Member

@matschik You can prefix the API routes, check out the documentation https://strapi.io/documentation/configurations/configurations.html#request

@decimoseptimo
Copy link

This doesn't work.
You can set the router in ./config/environments/**/request.json, but the html markup will still hard-link to /admin everywhere.

@WesselKoorn
Copy link

@Aurelsicoko Can you explain how that exactly works?

I want to host my Strapi application on a Nginx server on a custom route just as described above (mydomain.com/strapi for example) but I can't get it to work. I keep getting the same error when visiting mydomain.com/strapi and mydomain.com/strapi/admin:

{"statusCode":404,"error":"Not Found","message":"Not Found"}

I've got the same Nginx config as the original post:

location /strapi {
            proxy_pass         http://localhost:1337;
            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;
}

@derrickmehaffy
Copy link
Member

@WesselKoorn I don't recommend this, it can be done with some very complex nginx configs (you are basically going to have to map just about every endpoint for your API which would be crazy complex) or do some crazy regex magic.

Your best bet api.example.com for your Strapi API and example.com for your frontend. Easy, simple, and quick.

@WesselKoorn
Copy link

@derrickmehaffy Ok I will use a subdomain then, thanks for your reply!

@fahimalizain
Copy link

@derrickmehaffy Hi, even after using a subdomain,
It returns 404 for the main and runtime bundles.js files

http-200   api.example.com/dashboard
http-404   api.example.com/dashboard/runtime~main.338acfbb.js
http-404   api.example.com/dashboard/main.b480967e.chunk.js

and when accessed directly bypassing nginx and cloudflare:

http-200   <ip>:1337/dashboard
http-200   <ip>:1337/dashboard/runtime~main.338acfbb.js
http-200   <ip>:1337/dashboard/main.b480967e.chunk.js

It's all good then!

This is my nginx config, which is again behind Cloudflare

location / {
	proxy_pass                  http://localhost:1337/;
	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";
}

I have been at this for sometime now, any hints would be great :)

@derrickmehaffy
Copy link
Member

@faztp12 remove that trailing slash on your proxy_pass

Short little useful guide: https://dev.to/danielkun/nginx-everything-about-proxypass-2ona

@vivex
Copy link

vivex commented May 27, 2020

I am also using strapi installed in subroute domain.com/strapi , and i modified url: /strapi in config/server.js, Now domain.com/strapi/admin page is opening but domain.com/strapi/users-permissions/init api is throwing 404 error.

@derrickmehaffy
Copy link
Member

@vivex have you seen the new proxy documentation guides for the stable release? https://strapi.io/documentation/v3.x/getting-started/deployment.html#optional-software-guides

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: feature request Issue suggesting a new feature
Projects
None yet
Development

No branches or pull requests

8 participants