nyancat3 / private-isu-practice

MIT License
1 stars 0 forks source link

Make uploaded images static #5

Closed nyancat3 closed 3 days ago

nyancat3 commented 3 days ago

Initial score

{"pass":true,"score":9680,"success":8544,"fail":0,"messages":[]}
nyancat3 commented 3 days ago

Update /etc/nginx/sites-available/isucon.conf

server {
  listen 80;

  client_max_body_size 10m;
  root /home/isucon/private_isu/webapp/public/;

  location ~ ^/(favicon\.ico|css/|js/|img/) {
    expires 2d;
    root /home/isucon/private_isu/webapp/public/;
  }

  location / {
    proxy_set_header Host $host;
    proxy_pass http://localhost:8080;
  }
}

->

server {
  listen 80;

  client_max_body_size 10m;
  root /home/isucon/private_isu/webapp/public/;

  location ~ ^/(favicon\.ico|css/|js/|img/) {
    expires 2d;
    root /home/isucon/private_isu/webapp/public/;
  }

  location /image/ {
    root /home/isucon/private_isu/webapp/public/;
    expires 2d;
    try_files $uri @app;
  }

  location @app {
    internal;
    proxy_pass http://localhost:8080;
  }

  location / {
    proxy_set_header Host $host;
    proxy_pass http://localhost:8080;
  }
}
nyancat3 commented 3 days ago
/home/isucon/private_isu/webapp/public# ls
css  favicon.ico  img  js
/home/isucon/private_isu/webapp/public# mkdir image
/home/isucon/private_isu/webapp/public# ls
css  favicon.ico  image  img  js
/home/isucon/private_isu/webapp/public# ls -l
total 20
drwxrwxr-x 2 isucon isucon 4096 Jun  2 13:43 css
-rw-rw-r-- 1 isucon isucon   43 Jun  2 13:43 favicon.ico
drwxr-xr-x 2 root   root   4096 Dec  1 19:32 image
drwxrwxr-x 2 isucon isucon 4096 Jun  2 13:43 img
drwxrwxr-x 2 isucon isucon 4096 Jun  2 13:43 js
/home/isucon/private_isu/webapp/public# chmod 757 /home/isucon/private_isu/webapp/public/image
nyancat3 commented 3 days ago

Score

{"pass":true,"score":25486,"success":24007,"fail":0,"messages":[]}