nginx

Posted xiennnnn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx相关的知识,希望对你有一定的参考价值。

1.下载地址 https://nginx.org/download/ 解压

技术图片

2. 配置

yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

./configure --prefix=/usr/local/nginx

make make install

3.基本命令

./nginx 开启
./nginx -s stop 停止
./nginx -s quit
./nginx -s reload

4.配置conf 负载均衡demo

(1).随便写两个服务

a服务

# -*- coding: UTF-8 -*-
from flask import Flask, jsonify
from flask import request

app = Flask(__name__)


@app.route(‘/‘)
def hello_world():
return ‘GO!‘


if __name__ == ‘__main__‘:
app.run(host="0.0.0.0", port=5001, debug=False)

b服务

# -*- coding: UTF-8 -*-
from flask import Flask, jsonify
from flask import request

app = Flask(__name__)


@app.route(‘/‘)
def hello_world():
return ‘GO! XN‘


if __name__ == ‘__main__‘:
app.run(host="0.0.0.0", port=5000, debug=False)

(2)配置nginx 文件

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream group1{
server 192.168.203.137:5000 weight=5;
server 192.168.203.137:5001 weight=1;
}
server {
listen 80;
server_name localhost;
location /{
proxy_pass http://group1/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

(3)测试 http://ip/

访问6次 五次b服务 一次a服务

以上是关于nginx的主要内容,如果未能解决你的问题,请参考以下文章

NginxNginx配置REWRITE隐藏index.php

NginxNginx配置文件解析

NginxNginx基础操作

NginxNginx基础操作

NginxNginx基础操作

NginxNginx基础操作