문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| python:django:garam [2023/10/26 14:38] – [nginx] taekgu | python:django:garam [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| + | ====== 설정을 위하여 ====== | ||
| + | ===== garam.garamx.com ===== | ||
| + | |||
| + | ==== uWSGI ==== | ||
| + | |||
| + | === 1.uwsgi.ini === | ||
| + | |||
| + | |||
| + | <code bash garam/ | ||
| + | [uwsgi] | ||
| + | uid=foo | ||
| + | base=/ | ||
| + | |||
| + | # the virtualenv (full path) | ||
| + | home=/ | ||
| + | chdir=/ | ||
| + | |||
| + | module=conf.wsgi: | ||
| + | env=DJANGO_SETTINGS_MODULE=conf.settings.product | ||
| + | |||
| + | # process-related settings | ||
| + | # uWSGI 프로세스를 master로 돌아가게 해줍니다. | ||
| + | master=true | ||
| + | |||
| + | # maximum number of worker processes | ||
| + | processes=5 | ||
| + | |||
| + | max-requests=5000 | ||
| + | daemonize=/ | ||
| + | |||
| + | # UNIX socket 파일의 위치입니다. socket file의 위치를 잡아줘도 되며 localhost와 port를 명시해줘도 됩니다. | ||
| + | socket=/ | ||
| + | # UNIX socket 소유자 | ||
| + | chown-socket=%(uid): | ||
| + | # UNIX socket에 대한 권한 설정입니다. 666을 해야 실행이 가능합니다. | ||
| + | chmod-socket=660 | ||
| + | # uWSGI를 통해서 생성된 파일들은 삭제하는 옵션입니다. | ||
| + | vacuum=true | ||
| + | |||
| + | # thread 사용을 앱(uWSGI) 내에서 가능하게 해줍니다. | ||
| + | enable-threads = true | ||
| + | # 단일한 python interpreter를 사용하게 하는 옵션입니다. | ||
| + | single-interpreter = true | ||
| + | # master말고 각각의 worker에(master에서 spawn한 자식들) 앱을 로드하는 설정입니다. | ||
| + | lazy-apps = true | ||
| + | </ | ||
| + | |||
| + | === 2.uwsgi service 등록 === | ||
| + | |||
| + | <code bash / | ||
| + | [Unit] | ||
| + | Description=uWSGI Emperor service | ||
| + | |||
| + | [Service] | ||
| + | ExecStart=/ | ||
| + | --emperor / | ||
| + | User=foo | ||
| + | Group=www-data | ||
| + | Restart=on-failure | ||
| + | KillSignal=SIGQUIT | ||
| + | Type=notify | ||
| + | NotifyAccess=all | ||
| + | StandardError=syslog | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== nginx ==== | ||
| + | |||
| + | <code bash / | ||
| + | ## | ||
| + | # You should look at the following URL's in order to grasp a solid understanding | ||
| + | # of Nginx configuration files in order to fully unleash the power of Nginx. | ||
| + | # https:// | ||
| + | # https:// | ||
| + | # https:// | ||
| + | # | ||
| + | # In most cases, administrators will remove this file from sites-enabled/ | ||
| + | # leave it as reference inside of sites-available where it will continue to be | ||
| + | # updated by the nginx packaging team. | ||
| + | # | ||
| + | # This file will automatically load configuration files provided by other | ||
| + | # applications, | ||
| + | # available underneath a path with that package name, such as /drupal8. | ||
| + | # | ||
| + | # Please see / | ||
| + | ## | ||
| + | |||
| + | upstream django { | ||
| + | # server unix:/// | ||
| + | server unix:/// | ||
| + | } | ||
| + | |||
| + | # Default server configuration | ||
| + | # | ||
| + | server { | ||
| + | listen 80 default_server; | ||
| + | listen [::]:80 default_server; | ||
| + | |||
| + | # SSL configuration | ||
| + | # | ||
| + | # listen 443 ssl default_server; | ||
| + | # listen [::]:443 ssl default_server; | ||
| + | # | ||
| + | # Note: You should disable gzip for SSL traffic. | ||
| + | # See: https:// | ||
| + | # | ||
| + | # Read up on ssl_ciphers to ensure a secure configuration. | ||
| + | # See: https:// | ||
| + | # | ||
| + | # Self signed certs generated by the ssl-cert package | ||
| + | # Don't use them in a production server! | ||
| + | # | ||
| + | # include snippets/ | ||
| + | |||
| + | root / | ||
| + | |||
| + | # Add index.php to the list if you are using PHP | ||
| + | index index.html index.htm index.nginx-debian.html; | ||
| + | |||
| + | server_name _; | ||
| + | |||
| + | location / { | ||
| + | # First attempt to serve request as file, then | ||
| + | # as directory, then fall back to displaying a 404. | ||
| + | try_files $uri $uri/ =404; | ||
| + | } | ||
| + | |||
| + | # pass PHP scripts to FastCGI server | ||
| + | # | ||
| + | #location ~ \.php$ { | ||
| + | # include snippets/ | ||
| + | # | ||
| + | # # With php-fpm (or other unix sockets): | ||
| + | # | ||
| + | # # With php-cgi (or other tcp sockets): | ||
| + | # | ||
| + | #} | ||
| + | |||
| + | # deny access to .htaccess files, if Apache' | ||
| + | # concurs with nginx' | ||
| + | # | ||
| + | #location ~ /\.ht { | ||
| + | # deny all; | ||
| + | #} | ||
| + | } | ||
| + | |||
| + | |||
| + | # Virtual Host configuration for example.com | ||
| + | # | ||
| + | # You can move that to a different file under sites-available/ | ||
| + | # to sites-enabled/ | ||
| + | # | ||
| + | #server { | ||
| + | # listen 80; | ||
| + | # listen [::]:80; | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # root / | ||
| + | # index index.html; | ||
| + | # | ||
| + | # location / { | ||
| + | # | ||
| + | # } | ||
| + | #} | ||
| + | |||
| + | server { | ||
| + | |||
| + | # SSL configuration | ||
| + | # | ||
| + | # listen 443 ssl default_server; | ||
| + | # listen [::]:443 ssl default_server; | ||
| + | # | ||
| + | # Note: You should disable gzip for SSL traffic. | ||
| + | # See: https:// | ||
| + | # | ||
| + | # Read up on ssl_ciphers to ensure a secure configuration. | ||
| + | # See: https:// | ||
| + | # | ||
| + | # Self signed certs generated by the ssl-cert package | ||
| + | # Don't use them in a production server! | ||
| + | # | ||
| + | # include snippets/ | ||
| + | |||
| + | root / | ||
| + | |||
| + | # Add index.php to the list if you are using PHP | ||
| + | index index.html index.htm index.nginx-debian.html; | ||
| + | server_name garam.garamx.com; | ||
| + | |||
| + | location / { | ||
| + | return 301 /greed/; | ||
| + | } | ||
| + | |||
| + | location /naro { | ||
| + | # First attempt to serve request as file, then | ||
| + | # as directory, then fall back to displaying a 404. | ||
| + | # try_files $uri $uri/ =404; | ||
| + | uwsgi_pass django; | ||
| + | include / | ||
| + | } | ||
| + | |||
| + | location /static { | ||
| + | # alias / | ||
| + | alias / | ||
| + | } | ||
| + | |||
| + | location /greed { | ||
| + | sub_filter_types text/xml text/css text/ | ||
| + | #root / | ||
| + | #index index.html; | ||
| + | alias / | ||
| + | try_files $uri $uri/ / | ||
| + | } | ||
| + | |||
| + | # pass PHP scripts to FastCGI server | ||
| + | # | ||
| + | #location ~ \.php$ { | ||
| + | # include snippets/ | ||
| + | # | ||
| + | # # With php-fpm (or other unix sockets): | ||
| + | # | ||
| + | # # With php-cgi (or other tcp sockets): | ||
| + | # | ||
| + | #} | ||
| + | |||
| + | # deny access to .htaccess files, if Apache' | ||
| + | # concurs with nginx' | ||
| + | # | ||
| + | #location ~ /\.ht { | ||
| + | # deny all; | ||
| + | #} | ||
| + | |||
| + | |||
| + | listen [::]:443 ssl ipv6only=on; | ||
| + | listen 443 ssl; # managed by Certbot | ||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | include / | ||
| + | ssl_dhparam / | ||
| + | |||
| + | } | ||
| + | server { | ||
| + | if ($host = garam.garamx.com) { | ||
| + | return 301 https:// | ||
| + | } # managed by Certbot | ||
| + | |||
| + | listen 80 ; | ||
| + | listen [::]:80 ; | ||
| + | server_name garam.garamx.com; | ||
| + | return 404; # managed by Certbot | ||
| + | |||
| + | } | ||
| + | </ | ||