nginx (待更新)

install

  • apt install nginx
  • 默认在 /etc/nginx 目录下

  • 一个 master 以及多个 worker
 3504 root       20   0  141M  7196  5552 S  0.0  0.4  0:00.03 nginx: master process nginx
 6154 www-data   20   0  141M  3628  1828 S  0.0  0.2  0:00.00 `- nginx: worker process
 6152 www-data   20   0  141M  3628  1828 S  0.0  0.2  0:00.00 `- nginx: worker process

常用命令

  • nginx
  • nginx -s stop
  • nginx -s quit
  • nginx -s reload
  • nginx -s reopen

配置文件

events {
    worker_connections 768;
    # multi_accept on;
}
http {

    server {
        root /opt;

        location /test {
            root /etc;
        }
        location /tmp/ {
            root /home;
        }
    }
}

上面的这个配置文件:
path == test 的时候, eg: http://127.0.0.1/test/hello.txt 则 nginx 会 open /etc/test/hello.txt

path == /tmp , eg: http://127.0.0.1/tmp/hello.txt 则 nginx open /home/tmp/hello.txt

path != test and path != tmp eg:http://127.0.0.1/hello/hello.txt 则 nginx open /opt/htllo/hello.txt

  • 注意: location 中不定义 root 则会使用 server 中定义的 root

例如:

location / {
    # empty
}

反向代理

location /{
    proxy_pass http://google.com;
}

使用通配符

location ~\.(pdf|doc) {
    root /opt;
}
  • 所以 当存在
    location /{
    root /opt;
    }
    的时候, 不符合 test 并且不符合 tmp 的请求会转发到 /opt/path 下

管理

  • master pid
➜  nginx cat /var/run/nginx.pid
3504

查看日志

  • /var/log/nginx

命令:

  • /etc/init.d/nginx restart |start|stop
  • seservice nginx status

组成部分

user www-data;

worker_processes 1;

pid /run/nginx.pid;

events {

worker_connections 768;

}

http {

sendfile on;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 65;

types_hash_max_size 2048;

include /etc/nginx/mime.types;

default_type application/octet-stream;

access_log /var/log/nginx/access.log;

error_log /var/log/nginx/error.log;

gzip on;

gzip_disable "msie6";

include /etc/nginx/conf.d/*.conf;

include /etc/nginx/sites-enabled/*;

}

转载于:https://www.cnblogs.com/ywhyme/p/10556981.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值