nignx相關(guān)的基本操作(mac下)
1.nignx 當(dāng)前啟動的 配置文件路徑查找:命令? ? nginx -t??
2.nignx 安裝路徑查找:命令??ps? -ef | grep nginx
如下圖2: master process 后面就是 安裝目錄。如(/usr/local/Cellar/nginx/1.12.1/bin/nginx)
3.ningx 安裝啟動扮念,關(guān)閉 及重啟。
安裝
用brew 安裝:命令sudo brew install nginx
啟動:
1.用brew:命令sudo brew services start nginx
2.尋找默認(rèn)安裝目錄:命令??nginx -h
nginx version: nginx/1.12.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h: this help
-v: show version and exit
-V: show version and configure options then exit
-t: test configuration and exit
-T: test configuration, dump it and exit
-q: suppress non-error messages during configuration testing
-s signal: send signal to a master process: stop, quit, reopen, reload
-p prefix: set prefix path (default: /usr/local/Cellar/nginx/1.12.1/)
-c filename: set configuration file (default: /usr/local/etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file/usr/local/Cellar/nginx/1.12.1/ 為默認(rèn)安裝目錄
/usr/local/etc/nginx/nginx.conf 為默認(rèn)配置文件
啟動:
/usr/local/Cellar/nginx/1.12.1/bin/nginx -c /usr/local/etc/nginx/nginx.conf
關(guān)閉:命令 pkill nginx
強(qiáng)制關(guān)閉 :命令 sudo pkill -9 nginx
重啟:
? ? 1.kill -HUP 主進(jìn)程
????????????如上圖2: 命令??kill -HUP 12531
? ? 2.?nginx -s reload
? ? ? ?常用命令如下
nginx? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #啟動nginx
nginx -s quit? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#快速停止
nginx nginx -V? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #查看版本,以及配置文件地址
nginx -v? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #查看版本
nginx -s reload|reopen|stop|quit ???? #重新加載配置|重啟|快速停止|安全關(guān)閉
nginx -h??????????????????????????????????#幫助
node nignx代理 靜態(tài)資源處理?
注:配置文件路徑:/usr/local/etc/nginx/nginx.conf 贡茅。修改如下
1.location ~ ^/public/*? 此配置 [public 自定義 攔截Url里/public? 指定到指定目錄下]
????http://localhost:8080/public/index.html
? ? ? ? ? ? 會訪問/Users/ahu/WebstormProjects/node/ 目錄下的? index.html
????http://localhost:8080/public/test/test.html
? ? ? ? 會訪問/Users/ahu/WebstormProjects/node/test/ 目錄下的? test.html
2.location /此配置是
????nignx 反響代理? node 服務(wù)http://127.0.0.1:3001
? ? 訪問地址為http://localhost:8080
server {
listen? ? ? 8080;
server_name? localhost;
#charset koi8-r;
#access_log? logs/host.access.log? main;
location ~ ^/public/* {
root /Users/ahu/WebstormProjects/node;
access_log off;
expires max;
}
location / {
proxy_pass? ? http://127.0.0.1:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 1;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_set_header Host $host;
}
#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_index? index.php;
#? ? fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
#? ? include? ? ? ? fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#? ? deny? all;
#}
}