node nignx代理 靜態(tài)資源處理

nignx相關(guān)的基本操作(mac下)

1.nignx 當(dāng)前啟動的 配置文件路徑查找:命令? ? nginx -t??

圖1

2.nignx 安裝路徑查找:命令??ps? -ef | grep nginx

如下圖2: master process 后面就是 安裝目錄。如(/usr/local/Cellar/nginx/1.12.1/bin/nginx)

圖2

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;

#}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末爪瓜,一起剝皮案震驚了整個濱河市桐汤,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌掰派,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,110評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件狈究,死亡現(xiàn)場離奇詭異碗淌,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)抖锥,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,443評論 3 395
  • 文/潘曉璐 我一進(jìn)店門亿眠,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人磅废,你說我怎么就攤上這事纳像。” “怎么了拯勉?”我有些...
    開封第一講書人閱讀 165,474評論 0 356
  • 文/不壞的土叔 我叫張陵竟趾,是天一觀的道長。 經(jīng)常有香客問我宫峦,道長岔帽,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,881評論 1 295
  • 正文 為了忘掉前任导绷,我火速辦了婚禮犀勒,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘妥曲。我一直安慰自己贾费,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,902評論 6 392
  • 文/花漫 我一把揭開白布檐盟。 她就那樣靜靜地躺著褂萧,像睡著了一般。 火紅的嫁衣襯著肌膚如雪葵萎。 梳的紋絲不亂的頭發(fā)上导犹,一...
    開封第一講書人閱讀 51,698評論 1 305
  • 那天唱凯,我揣著相機(jī)與錄音,去河邊找鬼谎痢。 笑死波丰,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的舶得。 我是一名探鬼主播掰烟,決...
    沈念sama閱讀 40,418評論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼沐批!你這毒婦竟也來了纫骑?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,332評論 0 276
  • 序言:老撾萬榮一對情侶失蹤九孩,失蹤者是張志新(化名)和其女友劉穎先馆,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體躺彬,經(jīng)...
    沈念sama閱讀 45,796評論 1 316
  • 正文 獨居荒郊野嶺守林人離奇死亡煤墙,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,968評論 3 337
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了宪拥。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片仿野。...
    茶點故事閱讀 40,110評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖她君,靈堂內(nèi)的尸體忽然破棺而出脚作,到底是詐尸還是另有隱情,我是刑警寧澤缔刹,帶...
    沈念sama閱讀 35,792評論 5 346
  • 正文 年R本政府宣布球涛,位于F島的核電站,受9級特大地震影響校镐,放射性物質(zhì)發(fā)生泄漏亿扁。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,455評論 3 331
  • 文/蒙蒙 一鸟廓、第九天 我趴在偏房一處隱蔽的房頂上張望从祝。 院中可真熱鬧,春花似錦肝箱、人聲如沸哄褒。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,003評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至退客,卻和暖如春骏融,著一層夾襖步出監(jiān)牢的瞬間链嘀,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,130評論 1 272
  • 我被黑心中介騙來泰國打工档玻, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留怀泊,地道東北人。 一個月前我還...
    沈念sama閱讀 48,348評論 3 373
  • 正文 我出身青樓误趴,卻偏偏與公主長得像霹琼,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子凉当,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,047評論 2 355