安装之前需要依赖依赖,yum安装就完事了,网上很多这种
习惯在这个目录下安装程序
cd /usr/local
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar -zxvf nginx-1.6.2.tar.gz
cd /usr/local/nginx-1.6.2
./configure --prefix=/usr/local/nginx
make && make install
做个测试
/usr/local/nginx/sbin/nginx
ps -aux | grep nginx
查看是否启动
也可以访问浏览器访问 公网ip:80,看见欢迎ngnix
关闭
killall -9 nginx
修改配置文件能更便捷启动关闭
vim /etc/profile
文件末尾添加
PATH=$PATH:/usr/local/nginx/sbin
export PATH
更新配置文件
source /etc/profile
相当于ls软连接
nginx # 启动
nginx -s stop # 关闭
nginx -s reload # 重启
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
include uwsgi_params; # *主要加这两行,复制完删除这两行#*注释
uwsgi_pass 私网ip:8008; # *主要加这两行,其他能不动就不动吧
root html;
index index.html index.htm;
}
pip install uwsgi # 就行了
这是我项目目录
__pycache__目录没什么用
spider.py 是Crawl目录下的爬虫文件
manage.py 是flask主文件
log 日志
uwsgi.ini 新建uwsgi配置
.
└── projectFlask
└── hub0415
├── Crawl
│ ├── __pycache__
│ │ ├── spider.cpython-35.pyc
│ │ └── spider.cpython-36.pyc
│ └── spider.py
├── log
│ ├── uwsgi.log
│ └── uwsgi.pid
├── manage.py
└── uwsgi.ini
创建uwsgi.ini文件
vim /home/projectFlask/hub0415/uwsgi.ini
socket = 私网ip:8008
# python 启动程序文件
wsgi-file = /home/projectFlask/hub0415/manage.py
# 获取uwsgi统计信息的服务地址
stats = 私网ip:8080
# 在python文件中 app = Flask(__name__) 的app,否则500
callable = app
# 保存pid信息,方便停止服务和重启的时候用
pidfile = ./log/uwsgi.pid
# 后台运行时记录uwsgi的运行日志
daemonize = ./log/uwsgi.log
#更新py文件后重启wsgi
python-autoreload = 1
uwsgi软连接
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
uwsgi --ini /home/projectFlask/hub0415/uwsgi.ini
nginx -s reload
ps -aux | grep nginx
ps -aux | grep uwsgi
killall -9 uwsgi
killall -9 nginx
公网 39.100.20.111/lj/zf/bj/1
简易flask文件manage.py,就把pycharm基础helloworld模板改了一点点
from flask import Flask
from Crawl import spider
app = Flask(__name__)
@app.route('/lj/zf/bj/' )
def lj_rent(p):
'''
area = xihu/ xiacheng/ jianggan/ gongshu/ shangcheng/ binjiang/ yuhang/ xiaoshan/
fuyang/ linan/ qiantangxinqu/
'''
url = "https://hz.lianjia.com/zufang/binjiang/pg{}".format(p)
response = spider.page_get(url=url)
data = spider.page_parse(response)
return data
if __name__ == '__main__':
app.run(debug=True)