forked from Buthzz/trevio-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
204 lines (163 loc) · 6.08 KB
/
Copy pathnginx.conf
File metadata and controls
204 lines (163 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# ==========================================
# TREVIO PROJECT
# ==========================================
# --- 1. PRODUCTION (trevio.mfjrxn.eu.org) ---
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name trevio.mfjrxn.eu.org;
#root /var/www/trevio-prod;
root /var/www/trevio-prod/public;
index index.php index.html;
# SSL Keys
ssl_certificate /etc/letsencrypt/live/trevio.mfjrxn.eu.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/trevio.mfjrxn.eu.org/privkey.pem;
# --- SECURITY PRODUCTION ---
# 1. Matikan daftar file (Jika user buka folder, muncul 403 Forbidden)
autoindex off;
# 2. Sembunyikan versi Nginx (biar hacker ga tau versi berapa)
server_tokens off;
# 3. Security Headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# 4. Blokir file sensitif (.env, .git, .sql) -> WAJIB 403
location ~ /\.(?!well-known).* {
deny all;
}
# 5. Blokir akses langsung ke folder /app/ (Source Code)
location ~ ^/app/ {
deny all;
return 403;
}
# Logs
access_log /var/log/nginx/trevio_prod_access.log;
error_log /var/log/nginx/trevio_prod_error.log;
location / {
try_files $uri $uri/ /index.php?url=$uri&$args;
}
# PHP CONFIG (Sembunyikan Error di Browser)
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# PENTING: Jangan tampilkan error coding di layar user
fastcgi_param PHP_FLAG "display_errors=Off";
fastcgi_param PHP_ADMIN_VALUE "error_reporting=0";
}
# Menangani file gambar, css, js, font
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|webp|woff|woff2|ttf|eot)$ {
# 1. Simpan di cache browser selama 30 hari (Bikin website ngebut)
expires 30d;
# 2. Matikan log akses (Biar log server ga penuh sampah request gambar)
access_log off;
# 3. Header tambahan
add_header Cache-Control "public, no-transform";
# 4. Jika file tidak ada, jangan lempar ke PHP, langsung 404
try_files $uri =404;
}
# Blokir eksekusi PHP di folder uploads (Anti Shell/Backdoor)
location ^~ /uploads/ {
# Matikan PHP engine di folder ini
location ~ \.php$ { deny all; }
}
# Izinkan upload hingga 10MB (sesuaikan kebutuhan)
client_max_body_size 10M;
# Custom Error Pages
error_page 403 /errors/403;
error_page 404 /errors/404;
error_page 500 502 503 504 /errors/500;
# Route error pages through MVC
location ~ ^/errors/(403|404|500)$ {
rewrite ^/errors/(.*)$ /index.php?url=errors/$1 last;
}
}
# Redirect HTTP -> HTTPS (Prod)
server {
listen 80;
listen [::]:80;
server_name trevio.mfjrxn.eu.org;
return 301 https://$host$request_uri;
}
# --- 2. DEVELOPMENT (trevio-dev.mfjrxn.eu.org) ---
server {
listen 443 ssl;
listen [::]:443 ssl; # Support IPv6
server_name trevio-dev.mfjrxn.eu.org;
#root /var/www/trevio-dev;
root /var/www/trevio-dev/public;
index index.php index.html;
# SSL Keys
ssl_certificate /etc/letsencrypt/live/trevio.mfjrxn.eu.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/trevio.mfjrxn.eu.org/privkey.pem;
# --- FREEDOM DEVELOPMENT ---
# 1. Hidupkan daftar file (Agar GA 403 kalau buka folder aset/gambar)
autoindex on;
# 2. Security Headers (sama seperti prod)
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# 3. Tetap blokir .git dan .env
location ~ /\.(?!well-known).* {
deny all;
}
# 4. Blokir akses langsung ke folder /app/ (Source Code)
location ~ ^/app/ {
deny all;
return 403;
}
# Logs
access_log /var/log/nginx/trevio_dev_access.log;
error_log /var/log/nginx/trevio_dev_error.log;
location / {
try_files $uri $uri/ /index.php?url=$uri&$args;
}
# PHP CONFIG (Munculkan Error di Browser)
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# PENTING: Munculkan error coding langsung di layar (biar gampang fix bug)
fastcgi_param PHP_FLAG "display_errors=On";
fastcgi_param PHP_ADMIN_VALUE "error_reporting=E_ALL";
}
location = /report.html {
# 1. Ambil file dari ROOT folder (di luar public)
alias /var/www/trevio-dev/report.html;
default_type "text/html";
# 2. Paksa Browser Minta Password
#auth_basic "Restricted Area - Admin Only";
#auth_basic_user_file /etc/nginx/.htpasswd;
# 3. Matikan log akses buat file ini (biar log ga penuh sama admin sendiri)
access_log off;
}
# Menangani file gambar, css, js, font
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|webp|woff|woff2|ttf|eot)$ {
# 1. Simpan di cache browser selama 30 hari (Bikin website ngebut)
expires 30d;
# 2. Matikan log akses (Biar log server ga penuh sampah request gambar)
access_log off;
# 3. Header tambahan
add_header Cache-Control "public, no-transform";
# 4. Jika file tidak ada, jangan lempar ke PHP, langsung 404
try_files $uri =404;
}
# Custom Error Pages
error_page 403 /errors/403;
error_page 404 /errors/404;
error_page 500 502 503 504 /errors/500;
# Route error pages through MVC
location ~ ^/errors/(403|404|500)$ {
rewrite ^/errors/(.*)$ /index.php?url=errors/$1 last;
}
}
# Redirect HTTP -> HTTPS (Dev)
server {
listen 80;
listen [::]:80;
server_name trevio-dev.mfjrxn.eu.org;
return 301 https://$host$request_uri;
}