nginx (待更新)

install

  • apt install nginx
  • 默認在 /etc/nginx 目錄下node

  • 一個 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.txtnginx

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

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

  • 注意: location 中不定義 root 則會使用 server 中定義的 root

例如:tcp

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

}
相關文章
相關標籤/搜索