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

Nginx routing problem, possibly #622

Closed
h0adp0re opened this issue Feb 10, 2018 · 9 comments
Closed

Nginx routing problem, possibly #622

h0adp0re opened this issue Feb 10, 2018 · 9 comments
Assignees

Comments

@h0adp0re
Copy link

Node.js version:
8.9.4

npm version:
3.10.10

Strapi version:
3.0.0-alpha.9.3

Operating system:
Ubuntu 16.04

Do you want to request a feature or report a bug?
Report a bug

What is the current behavior?
Can't access Strapi via the browser. Chrome console:

Error parsing header X-XSS-Protection: 1; mode=block, 1; mode=block: expected semicolon at character position 14. The default protections will be applied.

VM5555:1 
GET https://mysite.com/admin/config/plugins.json 404 ()
(anonymous) @ VM5555:1
(anonymous) @ main.js:1
./admin/src/app.js @ main.js:1
t @ main.js:1
./admin/src/app.js @ main.js:1
(anonymous) @ main.js:1

main.js:1
TypeError: (e || []).forEach is not a function
    at main.js:1
    at <anonymous>

favicon.ico:1
GET https://mysite.com/favicon.ico 502 ()

If the current behavior is a bug, please provide the steps to reproduce the problem
Follow the deployment steps on Ubuntu and set up nginx like this:

server {
    listen 80 default_server;
    server_name _;
    return 444;
}

# HTTP - redirect all requests to HTTPS
server {
        listen 80;
        listen [::]:80;
        return 301 https://$host$request_uri;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl http2;
        server_name www.mysite.com;
        return 301 $scheme://mysite.com$request_uri;
}

# HTTPS - proxy requests on to local Node.js app
server {
        listen 443 ssl http2;
        server_name mysite.com;

        # Pass requests for / to localhost:8080
        location / {
                root /var/www/mysite.com/html;
                proxy_pass http://localhost:8080/;
        }

        # Pass requests for /admin to localhost:8181/admin/
        location /admin {
                root /var/www/admin/; # My Strapi installation folder is called admin
                proxy_pass http://localhost:8181/admin/;
        }

        location ~ /.well-known {
                allow all;
        }
}

What is the expected behavior?
Strapi can be accessed via the browser.

Other info

  • It's a totally fresh install of Strapi.
  • I followed the Deployment steps (set the host to mysite.com, changed the port to 8181 etc).
  • I use pm2 to run Strapi.
  • Connection with MongoDB is active with no errors.

I suspect something is wrong with my server blocks.

@rroblik
Copy link

rroblik commented Feb 12, 2018

Hi @henriollik

Here is what is did, working for me OOB :

upstream strapi {
    server 127.0.0.1:1337	max_fails=1 fail_timeout=5s;
}

server {
	listen   80;
	server_name strapi.localdomain;
	
	access_log "/var/log/nginx/strapi.access.log";
	error_log "/var/log/nginx/strapi.error.log";

        root /mnt/hgfs/_wprojects/strapi/public;
	
	index index.html;
	
	location / {
		try_files $uri $uri/ @strapi;
	}
	
	location @strapi{
		proxy_pass http://strapi;
	}
}

Note : you need to start strapi to let it work as backend on 1337 port (or any other configured)

$ strapi start

Regards

@lauriejim
Copy link
Contributor

Hi @henriollik your problem looks come from you server config.
So I hope the Strapi community will help you to solve your problem :)

@pierreburgy
Copy link
Member

Could you try with these instructions: https://medium.com/@strapi/how-to-deploy-a-strapi-api-on-ubuntu-16-04-17f8fbbf5c5b?

@h0adp0re
Copy link
Author

h0adp0re commented Feb 12, 2018

@lauriejim Thank you.

@rroblik I realize I can just use a subdomain for Strapi but I need to use a route. I got a test folder working with the same settings but Strapi doesn't seem to come through.

@pierreburgy I am aware of this blog post, however I need to use a route for accessing Strapi, and in the same file as my main domain, if possible.

I have a Polymer app on my domain and it hijacks all routes. So I need to set a definite route for Strapi on the server side. Creating a separate server block file for Strapi messed things up even further.

@lauriejim lauriejim assigned Aurelsicoko and unassigned lauriejim Feb 13, 2018
@lauriejim lauriejim added source: framework severity: medium If it breaks the basic use of the product but can be worked around issue: help wanted and removed status: wontfix severity: medium If it breaks the basic use of the product but can be worked around labels Feb 13, 2018
@lauriejim
Copy link
Contributor

lauriejim commented Feb 27, 2018

@henriollik Do you have update about your issue ?

@h0adp0re
Copy link
Author

h0adp0re commented Mar 3, 2018

@lauriejim I haven't tried anything new as I haven't had time to do so. So the issue still stands.

@lauriejim
Copy link
Contributor

lauriejim commented Mar 27, 2018

@henriollik As we can see, it's not an issue from Strapi that's why we set help wanted label. If you are not working on it I close this issue.

@crotel
Copy link

crotel commented Nov 2, 2018

Hi @henriollik

Here is what is did, working for me OOB :

upstream strapi {
    server 127.0.0.1:1337	max_fails=1 fail_timeout=5s;
}

server {
	listen   80;
	server_name strapi.localdomain;
	
	access_log "/var/log/nginx/strapi.access.log";
	error_log "/var/log/nginx/strapi.error.log";

        root /mnt/hgfs/_wprojects/strapi/public;
	
	index index.html;
	
	location / {
		try_files $uri $uri/ @strapi;
	}
	
	location @strapi{
		proxy_pass http://strapi;
	}
}

Note : you need to start strapi to let it work as backend on 1337 port (or any other configured)

$ strapi start

Regards

I had follow your way. port 80 url was ok, but url/admin can not open. why?

@h0adp0re
Copy link
Author

h0adp0re commented Jul 31, 2020

Hello @rroblik @lauriejim and @crotel. Sorry to necro this, but can I please ask of you all to edit my old username out of your comments?

Edit: it's pointless now since GH stores all edits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants