How?
Add reverse proxy to your next app inside default location block in Nginx's site configuration
location / {
# default port, could be changed if you use next with custom server
proxy_pass http://localhost:3000;
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;
# if you have try_files like this, remove it from our block
# otherwise next app will not work properly
# try_files $uri $uri/ =404;
}
Restart nginx server
$ sudo service nginx restart
Run next production app
- Build your app with
next build
- Start your app with pm2 or other process manager from production build directory
pm2 start npm --name "next" -- start
- Please note that if you are using a custom server, you will still need to start the custom server from its resident folder rather than running
next start
from the production build directory