Contoh Kasus

-
Client mau menampilkan 1 file saja dengan domain yang mereka miliki untuk kebutuhan tertentu.
Contoh, client punya domain client.com dan hanya ingin menampilkan file robots.txt saja http://client.com/robots.txt
Semua akses ke selain client.com/robots.txt akan di redirect ke http://client.com/robots.txt
-
Client mau menampilkan 1 file saja dengan domain yang mereka miliki untuk kebutuhan tertentu.
Bedanya, kali ini mereka ingin ekstensi file nya disembunyikan.
Contoh, client punya domain client.com dan hanya ingin menampilkan file config.json, tapi kali ini di redirect tanpa ekstensi (.json) jadi http://client.com/config
Semua akses ke selain http://client.com/config akan di redirect ke http://client.com/config
Solusi Kasus Pertama
- Siapkan 1 file robots.txt
User-agent: *
- Buat satu file virtual host nginx
server {
listen 88;
server_name localhost;
#server_name client.com
location /robots.txt {
#change root folder to your app folder
root /home/ipang/embersharing/pribados/blog-tutorials/onefile;
index robots.txt;
#always redirect to robots.txt even if
#user try to access subfolder
rewrite robots.txt/ /$1 permanent;
}
location / {
return http://localhost:88/robots.txt;
#return https://client.com/robots.txt
}
}

Bakal ke Robots.txt Terus
Solusi Kasus Kedua
- Siapkan 1 file, config.json
{
"nama": "ipang",
"website": "ipang.my.id"
}
- Buat satu file virtual host nginx
server {
listen 89;
server_name localhost;
location /nama {
root /home/ipang/embersharing/pribados/blog-tutorials/onefile;
index config.json;
#redirect all to config.json
rewrite ^/(.*)\.json /$1 permanent;
try_files $uri/config.json $uri.json $uri/ $uri /config.json;
}
location / {
return http://localhost:89/nama;
}
}

Ketik Apapun Balik Lagi ke /nama
File Docker Serve One File Only
-
Pastikan ada file berikut di dalam satu folder
Pastikan Semua File Ada di 1 Folder (nama.json harusnya config.json)
-
Untuk default.conf nya bisa di copy dari contoh di atas. Di sini saya copy yang kasus pertama
server {
listen 88;
server_name localhost;
#server_name client.com
location /robots.txt {
#change root folder to your app folder
root /home/ipang/embersharing/pribados/blog-tutorials/onefile;
index robots.txt;
#always redirect to robots.txt even if
#user try to access subfolder
rewrite robots.txt/ /$1 permanent;
}
location / {
return http://localhost:88/robots.txt;
#return https://client.com/robots.txt
}
}
- Buat file docker-compose.yml
version: "3.3"
services:
web:
image: nginx
container_name: nginx-ctr
ports:
- 88:88
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
- ./config.json:/usr/share/nginx/html/config.json

Jika kamu merasa tulisan ini bermanfaat & membantu kamu, kamu bisa berdonasi lewat saweria
If you feel this website help you, you can donate at saweria