Nginx 安装配置以及简单部署
安装
Centos
- 建议 yum install Nginx 简单安装
其他安装方法:
- wget http://nginx.org/download/ngi...
- tar -zxvf nginx-1.9.8.tar.gz
- cd nginx-1.9.8
- ./configure
- make && make install 或者 make 之后 make install
- 到此安装完成,安装路径为默认路径,具体路径看系统;查看路径命令:whereis nginx
Ubuntu
- 建议 apt install Nginx 简单安装
- 其他安装方法参考Centos安装方法;
配置 Nginx 服务器
Nginx 默认配置文件为 nginx.conf
- 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 }}