23/11/2026
Secure Website Deployment on Linux: Our Stack
A lot of people bring a site up, point the domain at it, and call it done. Then one day they find their admin panel indexed in Google. Or a basic scanner lists a pile of missing security headers.
A lot of people bring a site up, point the domain at it, and call it done. Then one day they find their admin panel indexed in Google. Or a basic scanner lists a pile of missing security headers.
On the ITcorv team we decided to show our own site instead of just talking. itcorv.ir runs right now with everything below. You can check every claim yourself with a curl; that's what the test section at the end is for.
This post is about the front layer: from the moment a request hits the server until it reaches the app. Hardening the server itself (SSH, firewall) is a separate topic.
What does secure website deployment on Linux mean?
Secure website deployment on Linux means bringing a site up so that, from day one, it's reachable through a single front door: forced HTTPS, security headers, a WAF in front of the app, the app and CMS bound to 127.0.0.1 or a separate subdomain, and the admin panel kept out of search results. Below we show exactly that with the real itcorv.ir setup.
The overall layout
It's simple:
- nginx sits in front of everything. It terminates TLS, sets the security headers, and runs the WAF.
- Next.js runs behind nginx and listens only on
127.0.0.1. You can't reach it directly from outside. - Directus, where we manage the site's content, runs on its own subdomain (
cms.itcorv.ir), also behind nginx.
Why? Because there's only one place that has to be configured right. Whatever the apps are, there's one front door. We covered nginx from scratch in our nginx post.
1. HTTPS only
The certificate comes from Let's Encrypt. It's free and certbot renews it automatically. Plain-http requests should get a 301 to https; we also send HSTS so browsers never try http again.
Then we turn on HSTS. This header tells the browser "for a year, open this domain over https only." So even if a user types http://, the browser goes straight to https.
One note: includeSubDomains means every subdomain must have https too. Before you enable it, make sure no subdomain is left without a certificate.
2. Security headers
We send these on every response:
X-Content-Type-Options: nosniff: the browser doesn't guess file types. Whatever the server says is what it is.X-Frame-Options: SAMEORIGIN: nobody can load the site inside an iframe on their own site (clickjacking).Referrer-Policy: strict-origin-when-cross-origin: when a user goes to another site, the full page URL doesn't leak, only the domain.Permissions-Policy: camera, microphone and geolocation are switched off entirely. Our site doesn't need them.
3. CSP, slowly
CSP (Content Security Policy) says where scripts, images and fonts are allowed to load from. Done right, it shuts down a lot of XSS attacks.
But if you make it strict overnight, half the site breaks. So we started with Content-Security-Policy-Report-Only. In this mode the browser blocks nothing; it just logs "this would have been blocked" in the console. That way we see what loads from where, then move toward enforcing it step by step.
4. A WAF in front of the app
nginx runs ModSecurity with the OWASP CRS rules. Suspicious requests, like a <script> in the URL, get a 403 before they ever reach Next.js. We walked through the setup in our WAF post.
5. A separate CMS, with noindex
The Directus panel lives on its own subdomain. We did two things there:
- It sends
X-Robots-Tag: noindex, nofollow, so Google doesn't index it and its login page never shows up in search results. - CORS only allows
https://itcorv.ir, so other sites can't call its API from a browser.
In Directus you set CORS with these env variables:
CORS_ENABLED=true
CORS_ORIGIN=https://example.com6. Caching
Next.js pre-renders pages and caches them with s-maxage and stale-while-revalidate. Most requests don't need to build the page from scratch at all. That's speed, and in a way security too: the server stays under less load.
Sample file
Here's a sample nginx config built on the same ideas. Swap in your own domain and paths. It assumes Next.js on port 3000 and Directus on port 8055 (its default).
# everything on port 80 goes to https
server {
listen 80;
listen [::]:80;
server_name example.com cms.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on; # nginx 1.25.1+
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
# security headers; always = also on error responses
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
add_header Content-Security-Policy-Report-Only "default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'; form-action 'self'" always;
# WAF (separate post)
modsecurity on;
modsecurity_rules_file /etc/nginx/modsec/main.conf;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
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_set_header X-Forwarded-Proto $scheme;
}
}
# CMS on its own subdomain
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name cms.example.com;
ssl_certificate /etc/letsencrypt/live/cms.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/cms.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Robots-Tag "noindex, nofollow" always;
location / {
proxy_pass http://127.0.0.1:8055;
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_set_header X-Forwarded-Proto $scheme;
}
}And start Next.js so it only listens locally:
npx next start -H 127.0.0.1 -p 3000The modsecurity lines only work if the module is installed. If you haven't installed it yet, comment them out for now.
After every change:
sudo nginx -t && sudo systemctl reload nginxTest
You can run all of these against our site too.
1. Headers:
curl -sI https://itcorv.irYou should see strict-transport-security, x-content-type-options, referrer-policy, x-frame-options, permissions-policy and content-security-policy-report-only.
2. TLS and certificate:
echo | openssl s_client -connect itcorv.ir:443 -servername itcorv.ir 2>/dev/null | grep -E 'Protocol|issuer'On our site you'll get TLSv1.3 and a Let's Encrypt issuer.
3. WAF:
curl -s -o /dev/null -w '%{http_code}\n' 'https://itcorv.ir/?q=<script>alert(1)</script>'It should return 403. If you get 200, the WAF isn't working.
4. CMS not indexed:
curl -sI https://cms.itcorv.ir | grep -i x-robots-tagYou should get noindex, nofollow.
5. The app is closed from outside: from another machine, run:
curl -m 5 http://SERVER-IP:3000You should get a timeout or connection refused. If a page comes back, the app is listening on 0.0.0.0 and you need to fix it.
There's also securityheaders.com, which grades your headers. Handy for a quick look.
Tips
add_headerin nginx has a trap: if alocationhas even oneadd_header, by default the ones from theserverblock no longer apply there. Either repeat them all, or put them in a file andincludeit.- Test HSTS with a short
max-agefirst. If something's broken, a one-year value keeps you stuck, because browsers remember it. - Don't enforce CSP overnight. Run report-only for a few days, watch the console, then switch.
- Never put the admin panel on the main domain. Separate subdomain, noindex, and an IP allowlist if you can.
- Anything that doesn't need to be seen from outside should listen on
127.0.0.1. That's the simplest firewall there is. - Running the app in Docker? Publish it as
127.0.0.1:3000:3000, not3000:3000. When to move to Kubernetes is covered in this post. - Test renewal by hand once:
sudo certbot renew --dry-run.
FAQ
Is all this needed for a simple site?
Most of it is a few lines of config and costs nothing. HTTPS, the headers and noindex on the admin panel belong on every site.
Why isn't your CSP enforced yet?
Because if CSP misses a source, that part of the site stops working. We first watch what loads in report-only mode, then tighten it.
Isn't X-Frame-Options outdated?
It's being replaced by frame-ancestors in CSP. But while our CSP is report-only, frame-ancestors doesn't block anything, so X-Frame-Options does the real work for now. Keeping it afterwards doesn't hurt, for older browsers.
Can you set this up for our site?
Yes. The ITcorv team does exactly this for organizations, from design to monitoring and 24/7 support.
Start from the consultation page, our DevOps services or our network security services.