如何本地安裝nginx及部署項目
1、下載
nginx官網(wǎng)地址:https://nginx.org/en/download.html
選擇遺留的穩(wěn)定版本:

解壓到任意位置

2、啟動
cmd 進(jìn)入nginx文件夾 輸入命令行:start nginx

打開瀏覽器,輸入: http://localhost:80 出現(xiàn)以下頁面即為啟動成功

3、部署項目
將項目放到nginx的html文件夾下

4、修改nginx的conf文件夾下的nginx.conf配置文件
配置說明:
- 1、listen:端口號
- 2、server_name:虛擬ip地址
- 3、root:聲明默認(rèn)網(wǎng)站根目錄位置 --項目的根目錄
- 4、index:定義首頁索引文件的名稱 --index.html
- 5、try_files:$uri $uri/ /app/index.html; 這里的設(shè)置是通過內(nèi)部重定向的方式,去匹配目錄下的索引文件index.html
- 6、location:控制服務(wù)訪問路徑
- 7、proxy_pass:請求代理轉(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下的常用命令
啟動:
直接點擊nginx目錄下的nginx.exe 或者
start nginx
關(guān)閉:
nginx -s stop
修改配置后重新加載生效并重啟nginx:
nginx -s reload
重新打開日志文件:
nginx -s reopen
測試nginx配置文件nginx.conf是否正確:
nginx -t -c /xxx/xx/nginx.conf
8、nginx實現(xiàn)同個ip、端口訪問不同的項目(以路徑區(qū)分項目)
nginx實現(xiàn)同個ip、端口訪問不同的項目(以路徑區(qū)分項目)
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
深入探究Nginx體系化之虛擬主機分類及配置實現(xiàn)
Nginx,這款備受推崇的高性能 Web 服務(wù)器,以其強大的性能和靈活的配置而廣受歡迎,在實際應(yīng)用中,虛擬主機是一項重要的功能,允許我們在單個服務(wù)器上托管多個網(wǎng)站,本文將深入探討 Nginx 虛擬主機的分類和配置實現(xiàn),幫助您構(gòu)建一個高效多站點托管平臺2023-08-08
Nginx配置srcache_nginx模塊搭配Redis建立緩存系統(tǒng)
這篇文章主要介紹了Nginx配置srcache_nginx模塊搭配Redis建立緩存系統(tǒng)的方法,文中關(guān)于Nginx模塊和Redis數(shù)據(jù)庫的安裝就不再說明了,這里只關(guān)注配置搭建階段,需要的朋友可以參考下2016-01-01
nginx外網(wǎng)訪問內(nèi)網(wǎng)站點配置操作
這篇文章主要介紹了nginx外網(wǎng)訪問內(nèi)網(wǎng)站點配置操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08
nginx?80端口配置多個location無效訪問404問題
這篇文章主要介紹了nginx?80端口配置多個location無效訪問404問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06

