nginx 설정 가이드

simuruk wiki

nginx aws에서 설치

  • sudo amazon-linux-extras install nginx1.12
  • sudo service status nginx.service
  • linux conf 위치: sudo vim /etc/nginx/nginx.conf

nginx 설정 예시

  1 user nginx;
  2 worker_processes auto;
  3 error_log /home/logs/nginx-error.log;
  4 pid /run/nginx.pid;
  5 
  6 include /usr/share/nginx/modules/*.conf;
  7 
  8 events {
  9     worker_connections 1024;
 10 }
 11 
 12 http {
 13     client_max_body_size 20m;
 14     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 15                       '$status $body_bytes_sent "$http_referer" '
 16                       '"$http_user_agent" "$http_x_forwarded_for"';
 17 
 18     access_log  /home/logs/nginx-access.log  main;
 19 
 20     sendfile            on;
 21     tcp_nopush          on;
 22     tcp_nodelay         on;
 23     keepalive_timeout   65;
 24     types_hash_max_size 2048;
 25 
 26     include             /etc/nginx/mime.types;
 27     default_type        application/octet-stream;
 28 
 29     include /etc/nginx/conf.d/*.conf;
 30 
 31     server {
 32         listen       80 default_server;
 33         listen       [::]:80 default_server;
 34         return 301   http://wiki.simuruk.com;
 35     }
 36 
 37     server {
 38         server_name wiki.simuruk.com;
 39         root /home/mediawiki;
 40         index index.php;
 41         autoindex off;
 42 
 43         client_max_body_size 5m;
 44         client_body_timeout 60;
 45 
 46         location / {
 47              try_files $uri $uri/ @rewrite;
 48         }
 49 
 50         # sitemap xml 위치
 51         location /sitemap {
 52         }
 53 
 54         # sitemap 생성 php 실행 url
 55         location /sitemap-update {
 56             fastcgi_param SCRIPT_FILENAME $document_root/RunMakeSitemap.php;
 57             include fastcgi_params;
 58             fastcgi_pass unix:/var/run/php-fpm.sock;
 59         }
 60 
 61         # google verification
 62         location /google1234.html {
 63             return 200 'google-site-verification: google1234.html';
 64         }
 65 
 66         # naver verification
 67         location /naver1234.html {
 68             return 200 'naver-site-verification: naver1234.html';
 69         }
 70 
 71         location @rewrite {
 72             rewrite ^/(.*)$ /index.php?title=$1&$args;
 73         }
 74 
 75          location ^~ /maintenance/ {
 76              return 403;
 77          }
 78 
 79         location ~ \.php$ {
 80             include fastcgi_params;
 81             fastcgi_pass unix:/var/run/php-fpm.sock;
 82             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 83         }
 84 
 85          location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
 86              try_files $uri /index.php;
 87              expires max;
 88              log_not_found off;
 89          }
 90 
 91          location = /_.gif {
 92              expires max;
 93              empty_gif;
 94          }
 95 
 96          location ^~ /cache/ {
 97              deny all;
 98          }
 99 
100          location /dumps {
101              root /home/mediawiki/local;
102              autoindex on;
103          }
104     }
105 }

참고링크