Nginx 安裝配置以及簡單部署

Nginx 安裝配置以及簡單部署

  • 安裝

    • Centoshtml

      • 建議 yum install Nginx 簡單安裝
      • 其餘安裝方法:node

      • 到此安裝完成,安裝路徑爲默認路徑,具體路徑看系統;查看路徑命令:whereis nginx
    • Ubuntunginx

      • 建議 apt install Nginx 簡單安裝
      • 其餘安裝方法參考Centos安裝方法;
  • 配置 Nginx 服務器

    • Nginx 默認配置文件爲 nginx.confweb

      • ubuntu 安裝會爲 用戶配置好各類配置,默認配置文件中會附贈一個實例,能夠直接在site-enabled文件夾中,新建一個配置文件;
user nginx;   // 默認便可
worker_processes auto;  // 默認設置自動選擇進程數量,能夠自行設置
error_log /var/log/nginx/error.log; // 錯誤信息存儲路徑
pid /run/nginx.pid;  // 進程信息保存文件

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;  // 最大鏈接數
}

http {
    // log信息輸出格式,能夠自行定義
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log  /var/log/nginx/access.log  main;  //指定日至文件的路徑及日誌記錄格式

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/site-enabled/*.conf;  // ubuntu 默認安裝,無需定義,若是沒有,能夠自行定義,定義的是conf配置文件的路徑以及名稱,必須定義在 http 塊中,Nginx會自動搜索相應的配置文件並加載
    
}
  • server 配置

    • 配置好主文件以後,主配文件不包含server塊,需額外的自行配置;默認配置以下:
upstream django {
    # server unix:/root/HHZS.sock; 
    server 127.0.0.1:8001; # for a web port socket (we'll use this first)
    // 轉發請求至 8001 端口與 uwsgi 進行通訊
}
 
 server {
    listen           80 default_server; // 默認監聽請求端口
    listen           [::]:80 default_server; // 同上
    charset         utf-8; // 默認編碼方式
    server_name      _;  // 默認ip訪問,能夠設置爲域名,經過域名訪問
    root             /usr/share/nginx/html;
    
    client_max_body_size 75M;   # adjust to taste
 
    # Django media
    location /imgs  { 
        alias /root/imgs;  # your Django project's media files - amend as required
    }

    location /statics {
        alias /root/hhsc2019/hhsc2019/statics; # your Django project's static files - amend as required

       uwsgi_read_timeout 120s;
    uwsgi_send_timeout 120s;
    proxy_read_timeout 1200;
    }
 
    location / { // 默認訪問路徑
        uwsgi_pass  django;
        include   /root/hhsc2019/uwsgi_params; # the uwsgi_params file you installed
  }
}
相關文章
相關標籤/搜索