服务器搭建

1. 购买域名,备案,购买服务器,获得备案号

2. 选择Linux版本,ubuntu16.04 64位

3. 更新系统

apt-get update
apt-get upgradepython

4. 安装git

apt-get install git
若要使用git clone 须要ssh-keygen -t rsa -C "your email@mail.com"
拷贝.ssh目录中的pub内容到github的SSH keys中mysql

5. 安装python(默认已经安装python2与python3),pip等,pip3有错误,须要修改,见另外一篇文章。

6. 虚拟环境搭建virtualenv

7. 安装mysql

  • 注意修改bind:127.0.0.1与权限分配

8. 关于uwsgi的安装与配置:

新建uwsgi.ini文件, 并配置linux

  • https://www.cnblogs.com/wswang/p/5521566.html
  • https://www.cnblogs.com/wongbingming/p/7106830.html

9. 安装nginx:

分为**源码**安装与**压缩包**稳定版安装,二者的文件安装目录不一样
`/etc/nginx/与/usr/local/nginx`

新建 uc_nginx.conf文, 并配置nginx

  • http://www.cnblogs.com/piscesLoveCc/p/5794926.htmlgit

  • https://www.jianshu.com/p/7cb1a824333egithub

  • https://blog.csdn.net/bestallen/article/details/52837609sql

10. 配置https证书

如今让咱们使用 [Let's Encrypt](https://letsencrypt.org/)提供的一个很好的HTTPS证书来提升咱们的应用程序的安全性。

设置HTTPS从未如此简单。更好的是,咱们如今能够免费得到它。他们提供了一个名为**certbot**的解决方案 ,负责为咱们安装和更新证书。这很是简单:

```shell
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
```

如今安装证书:

```shell
sudo certbot --nginx
```

而后就行了,证书和私钥位置在

```shell
/etc/letsencrypt/live/www.example.com/privkey.pem
```

只需按照提示操做便可。当被问及:

```tex
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
```
选择`2`将全部HTTP流量重定向到HTTPS。

证书是 90 天的,运行

```
$ sudo certbot renew --dry-run
```

Certbot 会帮你启动一个定时任务,在证书过时时自动更新

PS:云服务器上的安全组规则里记得把 443 端口开了。

经常使用命令

查看端口占用:netstat -ntpl 
查看进程:ps aux | grep nginx //查看nginx进程
查看端口占用状况:lsof -i:80 //查看80端口占用状况
杀死进程:kill -9 3274 //3274为进程PID

Nginx安装:apt-get install nginx
Nginx启动、中止和重启命令
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx reload

Nginx压缩包安装版:
Nginx启动、中止和重启命令
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -s reload
相关文章
相关标签/搜索