如何本地安裝nginx及部署項(xiàng)目
1、下載
nginx官網(wǎng)地址:https://nginx.org/en/download.html
選擇遺留的穩(wěn)定版本:
解壓到任意位置
2、啟動(dòng)
cmd 進(jìn)入nginx文件夾 輸入命令行:start nginx
打開(kāi)瀏覽器,輸入: http://localhost:80 出現(xiàn)以下頁(yè)面即為啟動(dòng)成功
3、部署項(xiàng)目
將項(xiàng)目放到nginx的html文件夾下
4、修改nginx的conf文件夾下的nginx.conf配置文件
配置說(shuō)明:
- 1、listen:端口號(hào)
- 2、server_name:虛擬ip地址
- 3、root:聲明默認(rèn)網(wǎng)站根目錄位置 --項(xiàng)目的根目錄
- 4、index:定義首頁(yè)索引文件的名稱 --index.html
- 5、try_files:$uri $uri/ /app/index.html; 這里的設(shè)置是通過(guò)內(nèi)部重定向的方式,去匹配目錄下的索引文件index.html
- 6、location:控制服務(wù)訪問(wèn)路徑
- 7、proxy_pass:請(qǐng)求代理轉(zhuǎn)發(fā)
server { listen 8011; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { try_files $uri $uri/ /index.html; #root html; #index index.html index.htm; } #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; #} }
5、重啟nginx
cmd 進(jìn)入nginx文件夾 輸入命令行:nginx -s reload
6、效果
7、nginx在windows下的常用命令
啟動(dòng):
直接點(diǎn)擊nginx目錄下的nginx.exe 或者
start nginx
關(guān)閉:
nginx -s stop
修改配置后重新加載生效并重啟nginx:
nginx -s reload
重新打開(kāi)日志文件:
nginx -s reopen
測(cè)試nginx配置文件nginx.conf是否正確:
nginx -t -c /xxx/xx/nginx.conf
8、nginx實(shí)現(xiàn)同個(gè)ip、端口訪問(wèn)不同的項(xiàng)目(以路徑區(qū)分項(xiàng)目)
nginx實(shí)現(xiàn)同個(gè)ip、端口訪問(wèn)不同的項(xiàng)目(以路徑區(qū)分項(xiàng)目)
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
深入探究Nginx體系化之虛擬主機(jī)分類及配置實(shí)現(xiàn)
Nginx,這款備受推崇的高性能 Web 服務(wù)器,以其強(qiáng)大的性能和靈活的配置而廣受歡迎,在實(shí)際應(yīng)用中,虛擬主機(jī)是一項(xiàng)重要的功能,允許我們?cè)趩蝹€(gè)服務(wù)器上托管多個(gè)網(wǎng)站,本文將深入探討 Nginx 虛擬主機(jī)的分類和配置實(shí)現(xiàn),幫助您構(gòu)建一個(gè)高效多站點(diǎn)托管平臺(tái)2023-08-08Nginx配置srcache_nginx模塊搭配Redis建立緩存系統(tǒng)
這篇文章主要介紹了Nginx配置srcache_nginx模塊搭配Redis建立緩存系統(tǒng)的方法,文中關(guān)于Nginx模塊和Redis數(shù)據(jù)庫(kù)的安裝就不再說(shuō)明了,這里只關(guān)注配置搭建階段,需要的朋友可以參考下2016-01-01nginx外網(wǎng)訪問(wèn)內(nèi)網(wǎng)站點(diǎn)配置操作
這篇文章主要介紹了nginx外網(wǎng)訪問(wèn)內(nèi)網(wǎng)站點(diǎn)配置操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08Nginx 請(qǐng)求壓縮的實(shí)現(xiàn)(動(dòng)態(tài)壓縮,靜態(tài)壓縮)
本文主要介紹了Nginx 請(qǐng)求壓縮的實(shí)現(xiàn)(動(dòng)態(tài)壓縮,靜態(tài)壓縮),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03解決nginx訪問(wèn)頁(yè)面中文亂碼的問(wèn)題
這篇文章主要為大家介紹了nginx訪問(wèn)頁(yè)面中文亂碼解決方案,文中有相關(guān)的代碼示例供大家參考,有需要的朋友可以借鑒參考下,希望能夠有所幫助2023-09-09nginx?80端口配置多個(gè)location無(wú)效訪問(wèn)404問(wèn)題
這篇文章主要介紹了nginx?80端口配置多個(gè)location無(wú)效訪問(wèn)404問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06