Nginx配置使用详解

本文详细介绍了Nginx的配置使用,包括常用命令、配置文件结构、反向代理、负载均衡、动静分离和高可用集群。重点讲解了server、location、反向代理配置以及负载均衡的多种策略,如轮询、权重分配、ip_hash和fair算法。还提到了root与alias在路径处理上的区别,并探讨了Nginx在高可用集群中的角色和配置。
摘要由CSDN通过智能技术生成

1、常用命令

需要进入nginx的安装目录中的sbin目录(也可以配置环境变量,在任何目录都可以执行下面的命令),里面有一个nginx脚本文件
在这里插入图片描述

1、启动nginx
    ./nginx
2、关闭nginx
	./nginx -s stop
3、重新加载nginx (nginx.conf)
	./nginx -s reload
4、查看版本号
	./nginx -v

2、Nginx配置文件(nginx.conf)

2.1概述

默认在Linux上安装的Nginx,配置文件在安装的nginx目录下的conf目录下,名字叫做nginx.conf

nginx.conf主要由三部分组成

  • 全局块,
  • events块
  • http块

2.2配置文件结构

在这里插入图片描述

2.3真实配置文件概览

# 全局快
------------------------------------------------------------------------------
#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块
events {
    worker_connections  1024;
}

# http块 
http {
------------------------------------------------------------------------------# http全局块
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;        
------------------------------------------------------------------------------    
# server块
server {
# server全局块
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

# location块
        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ .php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_ind
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值