Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Nginx router mapping issues with nextJS #93

Open
itranga opened this issue Oct 30, 2018 · 3 comments
Open

Nginx router mapping issues with nextJS #93

itranga opened this issue Oct 30, 2018 · 3 comments
Labels

Comments

@itranga
Copy link

itranga commented Oct 30, 2018

Hi ,
I have the following issues with the deployment in Nginx .Please help me to sort out .

Ex: www.test.com ---->it will show wordpress site (this is working )
www.test.com/order/ ---->it should show nextJS site (this is the one need to be sort out.)

but in the current situation it shows the page not found.
"Page Not Found The page /_error does not exist."

My nginx configuration has been given below .

location /site {
gzip_static on;
# try_files $uri $uri/ /index.html;
proxy_pass http://127.0.0.1:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_max_temp_file_size 0;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
# proxy_cache STATIC;
proxy_cache_valid 200 30m;
proxy_cache_valid 404 1m;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
proxy_hide_header X-powered-by;
}

Thanks

@iaincollins
Copy link
Owner

iaincollins commented Dec 4, 2018

Hi! Sorry for the delay in response.

If you create a next.config.js in the project root directory and use option assetPrefix it should work for you.

// next.config.js
module.exports = {
  assetPrefix: '/order/'
};

If you use dotenv and .env files you can make this option an environment variable so you can have different values for local development and production:

// next.config.js
require('dotenv').config()

module.exports = {
  assetPrefix: process.env.PREFIX
};

@iaincollins
Copy link
Owner

I have used this option with nginx to handle the proxying before and can confirm this is possible and works well. :-) I don't have an example config for this to hand, but if you are having trouble and would like an example, just let me know.

@iaincollins
Copy link
Owner

Going to close this, but if it's not working for anyone, or I've forgotten something do leave a comment.

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

No branches or pull requests

2 participants