IT STORY

Nginx 서버블록 예시

푸우시로 2024. 4. 29. 23:44
반응형

참으로 오랜만에 블로그 포스팅을 합니다. ㅠㅠ

 

최근에 Nginx 웹서버에 워드프레스 사이트 제작을 테스트 하고 있습니다.

기록도 할겸 ..  제가 웹서버 구축할때 사용하는 서버블록을 올립니다.

 

필요한 분들 맘껏 퍼가세요~

 

참고로 Pingdom Website Speed Test 할때 자주 뜨는 이슈들을 해결해논 블럭임을 말씀드립니다.

( 주소 : https://tools.pingdom.com/)

 

이슈해결 항목 : 

- Compress components with gzip

- Add Expires headers

- Make fewer HTTP requests

 

 


server {
        listen 80 default_server;

        server_name example.com 
http://www.example.com;

        return 301 https://$server_name$request_uri;
}

server {
        listen 443 ssl http2 default_server;

        server_name example.com 
http://www.example.com;

        root /var/www/example.com/html;

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
        ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
        ssl_dhparam /etc/ssl/certs/dhparam.pem;

        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256;
        ssl_ecdh_curve secp384r1;
        ssl_session_timeout 10m;
        ssl_session_cache shared:SSL:10m;
        ssl_session_tickets off;
        ssl_stapling on;
        ssl_stapling_verify on;
        resolver 1.1.1.1 1.0.0.1 valid=300s;
        resolver_timeout 5s;

        add_header Strict-Transport-Security max-age=31536000;
        add_header X-Content-Type-Options "nosniff" always;
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-XSS-Protection "1; mode=block" always;

        gzip on;
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        
gzip_types image/svg+xml text/plain text/xml text/css text/javascript application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript application/x-font-ttf application/vnd.ms-fontobject font/opentype font/ttf font/eot font/otf;

        location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf|svg)$ { expires 365d; }
        location ~* \.(pdf|html|swf)$ { expires 90d; }

        index index.php index.html index.htm;

        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        }

        client_max_body_size 0;
}

 

 

# 참고자료

 

- https://www.wpfastestcache.com/tutorial/how-to-enable-gzip-compression-in-wordpress/#advantage

 

How to Enable Gzip Compression in WordPress

In this tutorial, we will share 3 methods that will teach you how to enable gzip compression in WordPress sites.

www.wpfastestcache.com

- https://developer.wordpress.org/advanced-administration/performance/optimization/#Caching

 

WordPress Developer Resources | Official WordPress Developer Resources | Developer.WordPress.org

Official WordPress developer resources including a code reference, handbooks (for APIs, plugin and theme development, block editor), and more.

developer.wordpress.org

- https://tiprelay.com/%EC%9B%8C%EB%93%9C%ED%94%84%EB%A0%88%EC%8A%A4%EC%97%90-expires-%ED%97%A4%EB%8D%94-%EC%B6%94%EA%B0%80-%EB%B0%A9%EB%B2%95/

 

워드프레스에 Expires 헤더 추가 방법

워드프레스 웹 사이트에 Expires 헤더를 추가하면 브라우저에 파일을 캐시하고 서버에 요청하는 대신 브라우저에서 직접 파일을 제공하도록 지시합니다. Expires 헤더에서 브라우저가

tiprelay.com

 

반응형