第三阶段 - Nginx 配置


3.1 安装 Nginx

sudo apt install nginx

3.2 修改 nginx.conf

  • 切换到 nginx 目录下
cd /etc/ngnix 
  • nginx.conf 文件内容如下 ( 修改文件相应部分 , 或 直接清空文件 完全复制以下内容 )
user  root;
worker_processes  1;

events {
  worker_connections  1024;
}

http {
   include       mime.types;
   default_type  application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;


   server {
       listen 80 default_server;
       server_name _;
       
       return 404;
   }

   server {
       listen       80;
       server_name  你的域名    www.你的域名;    #省略www也要写 下面要做301跳转

       if ($host = "你的域名" ) {
           rewrite ^/(.*)$ http://www.你的域名/$1 permanent;    #301跳转
       }

       charset utf-8;

       location / {

           gzip on;    #gzip网站压缩
           gzip_http_version 1.1;
           gzip_comp_level 3;
           gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-ms-bmp;


           include uwsgi_params;  #主要添加这个
           uwsgi_connect_timeout 30;
           uwsgi_pass unix:/home/ubuntu/你的项目文件夹/uwsgi.sock;  #主要这个
           index index.html index.htm;
           client_max_body_size 75M;
      }

       location /static {
           alias /home/ubuntu/你的项目文件夹/static;#主要这个
           index index.html index.htm;
       }

       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }

   }

}

3.3 启动 Nginx

sudo service nginx restart
  • 正常运行后 , 浏览器输入你的域名进行测试 ( 不带 8000端口 )

3.3.1 附 Nginx相关命令

  • 启动 / 重启 - sudo service nginx restart
  • 查看进程 - sudo service nginx status
  • 停止Nginx - sudo service nginx stop

此时 uWSGI + Nginx 配置已完毕 , 如需要配置 https 访问 ( 比如对接 微信小程序 ), 则进行下一步


>>点击查看第四阶段<<

>>点击返回导航目录<<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值