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/*;

}
posted @ 2019-03-19 10:31  两只老虎111  阅读(144)  评论(0编辑  收藏  举报