#How Do I Serve My Site With Nginx?
59 messages ยท Page 1 of 1 (latest)
๐ This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
๐ต๏ธ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
โ
You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
in next.config.js, I have output: 'export', distDir: 'build', trailingSlash: true. There is build/{BUILD_ID,build-manifest.json,cache/,export-marker.json,images-manifest.json,server,static} and lots more JSON files.
In build/server, I see middleware-build-manifest.js, middleware*.js, middleware-manifest.json, font-manifest.json, chunks/, and some others.
Are you hosting a static site? You would serve your site using nginx typically by running
npm run build
then
npm run start
I'm not sure what a static site is. The javascript, HTML, CSS, etc. don't change, but the site fetches data from a REST server.
I don't think npm run start is the right way because it will run webpack dev server (maybe) or some other server, not nginx.
nginx is a service on the box that serves as your ssl reverse proxy
I use nginx in my production environment
on the box you should be able to do systemctl status nginx
I see what you're saying. I would like to serve a static site without using a reverse proxy to a Next.js server.
Reading!
After running next build, Next.js will generate the following files
/out/index.html
...
This is not my experience. As mentioned above, I see:
build/{BUILD_ID,build-manifest.json,cache/,export-marker.json,images-manifest.json,server,static}and lots more JSON files.
(build, notoutbecause in the configuration, I havedistDir: 'build'.) Noindex.html.
did you follow this part in your next.config.js?
output: 'export',
// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
// trailingSlash: true,
// Optional: Prevent automatic `/me` -> `/me/`, instead preserve `href`
// skipTrailingSlashRedirect: true,
// Optional: Change the output directory `out` -> `dist`
// distDir: 'dist',
}
Yes. As mentioned above, my config looks like this: output: 'export', distDir: 'build', trailingSlash: true.
Okay. one sec, let me test it locally
I set it up just like you and I have a index.html inside the build folder
I have a meeting I gotta get to, will be a min before I can respond
Oh are you using pages dir?
๐ฆ
No sweat, I'm not in a hurry.
build
โโโ BUILD_ID
โโโ build-manifest.json
โโโ cache
โย ย โโโ config.json
โย ย โโโ next-server.js.nft.json
โย ย โโโ swc
โย ย โย ย โโโ plugins
โย ย โย ย โโโ v3
โย ย โโโ webpack
โย ย โโโ client-production
โย ย โย ย โโโ 0.pack
โย ย โย ย โโโ index.pack
โย ย โโโ server-production
โย ย โโโ 0.pack
โย ย โโโ index.pack
โโโ export-marker.json
โโโ ... json files
โโโ server
โย ย โโโ chunks
โย ย โย ย โโโ 491.js
โย ย โย ย โโโ 582.js
โย ย โย ย โโโ 656.js
โย ย โย ย โโโ 664.js
โย ย โย ย โโโ 676.js
โย ย โย ย โโโ font-manifest.json
โย ย โโโ font-manifest.json
โย ย โโโ middleware-build-manifest.js
โย ย โโโ ...
โย ย โโโ pages
โย ย โย ย โโโ 404.html
โย ย โย ย โโโ 500.html
โย ย โย ย โโโ admin
โย ย โย ย โย ย โโโ open.html
โย ย โย ย โย ย โโโ open.js.nft.json
โย ย โย ย โโโ _app.js
โย ย โย ย โโโ _app.js.nft.json
โย ย โย ย โโโ _document.js
โย ย โย ย โโโ _document.js.nft.json
โย ย โย ย โโโ _error.js
โย ย โย ย โโโ _error.js.nft.json
โย ย โย ย โโโ index.html
โย ย โย ย โโโ index.js.nft.json
โย ย โโโ pages-manifest.json
โย ย โโโ webpack-runtime.js
โโโ static
โย ย โโโ 2sku5TNySjGyDuFk2_Epn
โย ย โย ย โโโ _buildManifest.js
โย ย โย ย โโโ _ssgManifest.js
โย ย โโโ chunks
โย ย โย ย ...
โย ย โย ย โโโ main-be43d357da86e0af.js
โย ย โย ย โโโ pages
โย ย โย ย โย ย โโโ admin
โย ย โย ย โย ย โย ย โโโ open-9e8231543f6df1ed.js
โย ย โย ย โย ย โโโ _app-5fb3e62960cc86ec.js
โย ย โย ย โย ย โโโ _error-a4ba2246ff8fb532.js
โย ย โย ย โย ย โโโ index-91ca2e3e527e8844.js
โย ย โย ย โโโ polyfills-c67a75d1b6f99dc8.js
โย ย โย ย โโโ webpack-14a891bf35ecde1d.js
โย ย โโโ css
โย ย ...
โย ย โโโ f2d4fdccce5c1d99.css
โโโ trace
I had to trim because Discord won't let me send the whole thing.
I do have pages/ , it's just in the wrong spot.
Oh are you using pages dir?
I had read that as, "do you have a pages dir [in the output directory]?", and thought I answered it. In the repository is apages/with several tsx files:index.tsx,login.tsx,_app.tsx, etc. and some .scss files.
You have middleware in your project? Its unsupported.
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
trailingSlash: true,
distDir: 'build',
};
export default nextConfig;
This is what your next.config.mjs should look like.
In your nextjs project are you using page router or app router? I was testing using the app router.
@narrow pine
good question!
If your using the 'page router' im going to have a little more difficulty helping lol I dont have any test projects using the pages router as its I would say obsolete, though still supported.
No sweat
With all that being said, your static files are just
โ โโโ pages
โ โ โโโ 404.html
โ โ โโโ 500.html
โ โ โโโ admin
โ โ โ โโโ open.html
โ โ โ โโโ open.js.nft.json
โ โ โโโ _app.js
โ โ โโโ _app.js.nft.json
โ โ โโโ _document.js
โ โ โโโ _document.js.nft.json
โ โ โโโ _error.js
โ โ โโโ _error.js.nft.json
โ โ โโโ index.html
Slap everything in the pages dir and I think you would have your static site.
I have a lot of import { useRouter } from "next/router"; does that answer the question?
Negative. What does this look like on your side
mine says app, does yours say pages?
Yeah thats fine, thats optional for organization
Based on what I seee your entry point is index.html here.
You can disregard all the other stuff I think
I tried something like rm -r *.json ...etc...; mv server/pages/* . and serve that. I got the index.html, but no CSS, and nothing worked.
Gotcha.... is your project have any secrets in it? If you can share it and I can build on locally I might be able to help I just dont have any projects that use the page router.
You can sanitize your project if you want as well, and send that
Sorry, bank account woes distracting me! The project is sensitive...
I have another project that uses page routing and serves static assets after npm run build. I have been having difficulty finding what the difference between that project and this one is. I think I'll dig deeper in that direction.
It almost looks like its still trying to build the project normally like it would in the .next folder. Can you verify there is nothing else in next.config.mjs and looks exactly like this?
const nextConfig = {
output: 'export',
trailingSlash: true,
distDir: 'build',
};
export default nextConfig;
Thank you for checking back, and sorry for the delay! I had module.exports = {... I changed to exactly what you have, and I get, "SyntaxError: Unexpected token 'export'" when building.
If I use /** @type {import('next').NextConfig} */module.exports={output:'export',trailingSlash:true,distDir:'build'}; I get the same problematic build directory.
(that's just an adjustment of your example.)
WHOAA!! I read the output of npm run build more carefully:
warn - Invalid next.config.js options detected:
- The value at .output must be one of: "standalone".
Reading!!
package.json has "next": "^12.0.7"...this app is like three months old...why on earth?
Okay, we'll update this and see where it lands. I assume that will fix everything. @supple crow u da man.
Someone messed up! haha
Yeah, I didn't set this one up... ๐คท๐ปโโ๏ธ