nginx编译配置

源码编译

./configure --prefix=/home/fdfs/nginx_bin --add-module=/home/yuqing/fastdfs-nginx-module/src
make&&make install

基本命令

帮助命令:nginx -h
版本命令:nginx -v
编译命令:nginx -V
启动命令: ./nginx
查看进程: ps aux | grep nginx
检查配置文件:sudo nginx -t
指定启动配置文件:sudo nginx -c /usr/local/nginx/conf/nginx.conf
暴力停止服务:sudo nginx -s stop
优雅停止服务:sudo nginx -s quit
重新加载配置文件:sudo nginx -s reload

nginx代理静态网页

vim /etc/nginx/nginx.conf

# nginx.conf
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$time_local | $host | $status | $request_length | $bytes_sent | $upstream_addr | $upstream_response_time | '
                      '$http_referer | $remote_addr | $remote_user | $request | $request_uri | '
                      '$http_user_agent | $http_x_forwarded_for | $cookie_Mac';

    log_format  api_main  escape=json '$time_local | $host | $status | $request_length | $bytes_sent | $upstream_addr | $upstream_response_time | '
                      '$http_referer | $remote_addr | $remote_user | $request | '
                      '$http_user_agent | $http_x_forwarded_for | $cookie_Mac | $http_authorization | $request_body';

    access_log  /var/log/nginx/access.log  main;
    client_max_body_size     1024m;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   35;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}

vim /etc/nginx/conf.d/eval.conf

#eval.conf
server {
    listen 3020;
    server_name 192.168.110.21;
    access_log /var/log/nginx/eval.log api_main;
    root /home/hyc/eval/html/dist/;
    location / {
        try_files $uri /index.html;
    }
}

nginx负载均衡

#user  nobody;
worker_processes  1;


events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    #在server上添加此upstream节点
    upstream mytomcat{
    #分权 即访问131与134的次数比例为1比1
        server localhost:5001 weight=1;  #springboot1 内置tomcat运行的端口
        server localhost:5002 weight=1;  #springboot2 内置tomcat运行的端口
        server localhost:5003 weight=1;  #springboot3 内置tomcat运行的端口
        }
        
    # HTTPS server
    server {
        listen 5000 ;
        server_name localhost;
        #即所有请求都到这里去找分配
        location / {
       #使用mytomcat分配规则,即刚自定义添加的upstream节点
           proxy_pass http://mytomcat;
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值