Nginx学习笔记

nginx-windows

Nginx官网

nginx -v # 查看nginx的版本号

start nginx # 启动nginx

nginx -s stop # 快速停止或关闭nginx

nginx -s quit # 正常停止或关闭nginx

nginx -s reload # 配置文件nginx.conf修改重装载命令

nginx-linux

nginx官网

解压包后cd进去,执行./configure检查安装环境,没有的环境要安装对应软件,之后执行make编译安装软件,再执行make install安装,默认安装在/usr/local/nginx下

nginx.config配置

#user  nobody;
worker_processes  1;
# 错误日志存放路径 日志级别
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    # 最大连接数
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    # 负载均衡:upstream可设置多个
    # 默认轮询模式
    # backup 热备模式
    # weight 权重模式
    # ip_hash ip地址hash
    upstream localhost{
        # ip_hash; # ip地址hash解决session共享问题
        server 127.0.0.1:8080;
        # server 127.0.0.1:8081 backup;
        # server 127.0.0.1:8082 weight=2;
    }
    server {
        listen       80; # 监听端口
        server_name  localhost; # 访问地址
        root /data; # 前端静态工程路径
        index index.html; # 默认页
        location / {
            # 防止带后缀的页面刷新报404
            try_files $uri $uri/ /index.html;
            # 让后端获取真实ip,而不是nginx的ip
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass   http://localhost:8081/; # 反向代理地址
        }
        # 缓存配置
        location ~ .*\.(gif|jpg|png|html|mp3)${
            expires 6h;
        }
        location ~ .*\.(js|css)?${
            expires 2h;
        }
        access_log /data/logs/nginx/app_access.log; #日志文件路径

        # 干掉路径中的/prod-api
#       location ^~/prod-api/ {
#           proxy_pass   http://localhost:8081/;
#           proxy_http_version 1.1;
#           proxy_set_header Upgrade $http_upgrade;
#           proxy_set_header Connection "upgrade";
#       } 
        
#        location ^~/prod-api/ {
#            # 后端的真实接口
#          proxy_pass http://localhost:8081;
#          proxy_redirect off;
#          proxy_set_header Host $host;
#          proxy_set_header X-Real-IP $remote_addr;
#          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#          proxy_set_header   Cookie $http_cookie;
#          # for Ajax
#          #fastcgi_param HTTP_X_REQUESTED_WITH $http_x_requested_with;
#          proxy_set_header HTTP-X-REQUESTED-WITH $http_x_requested_with;
#          proxy_set_header HTTP_X_REQUESTED_WITH $http_x_requested_with;
#          proxy_set_header x-requested-with $http_x_requested_with;
#          client_max_body_size 10m;
#          client_body_buffer_size 128k;
#          proxy_connect_timeout 90;
#          proxy_send_timeout 90;
#          proxy_read_timeout 90;
#          proxy_buffer_size 128k;
#          proxy_buffers 32 32k;
#          proxy_busy_buffers_size 128k;
#          proxy_temp_file_write_size 128k;
#        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值