包含标签 nginx 的文章

用nginx部署flask

安装uWSGI https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html apt-get install build-essential python3-dev pip3 install uwsgi 使用uWSGI 运行 运行uwsgi,假设有run.py并且使用python3 run.py可以运行项目 uwsgi --socket 0.0.0.0:5000 --protocol=http -w run:app 配置文件 创建uwsgi.ini [uwsgi] module = run:app master = true processes = 5 http = 0.0.0.0:5000 使用配置文件运行 uwsgi --ini uwsgi.ini 如果要使用nginx,应该使用socket [uwsgi] module = run:app master = true processes = 5 socket = /tmp/flask.sock chmod-socket = 666 chdir = {path} logto = {path} 添加一个服务 使用systemd 创建一个文件uwsgiproject.service……

阅读全文

禁止cloudflare以外的ip访问nginx的网站

添加一个文件cf.conf,里面记录的是允许访问的ip # https://www.cloudflare.com/ips # IPv4 allow 173.245.48.0/20; allow 103.21.244.0/22; allow 103.22.200.0/22; allow 103.31.4.0/22; allow 141.101.64.0/18; allow 108.162.192.0/18; allow 190.93.240.0/20; allow 188.114.96.0/20; allow 197.234.240.0/22; allow 198.41.128.0/17; allow 162.158.0.0/15; allow 104.16.0.0/12; allow 172.64.0.0/13; allow 131.0.72.0/22; # IPv6 allow 2400:cb00::/32; allow 2606:4700::/32; allow 2803:f800::/32; allow 2405:b500::/32; allow 2405:8100::/32; allow 2a06:98c0::/29; allow 2c0f:f248::/32; 修改 /etc/nginx/sites-available/default中的内容,添加include cf.conf和deny all location / { include /etc/nginx/cf.conf; deny all; # First attempt to serve request as file, then # as directory, then fall back to displaying a 404.……

阅读全文

nginx 多个location

在 /var/www/www2 目录下新建html文件index.html。 /var/www# tree . ├── html │ ├── index.nginx-debian.html │ └── test.php └── www2 └── index.html 配置的目录在 /etc/nginx 在conf.d中新建配置文件 此处我新建的是www2.conf server { listen 80; server_name ip_address; #此处是ip地址或者域名 location /www2 { alias /var/www/www2; index index.html index.php index.htm; } } 保存并且退出 用下面的命令检查一下是否出现错误 sudo nginx -s reload 或者直接重启 sudo /etc/init.d/nginx restart 访问ip_address/www2……

阅读全文