windows10使用nginx啓動web項目

啓動

安裝nginx後,進入nginx根目錄, cmd環境執行 start nginx.exe ,便可啓動.html

進入 http://127.0.0.1/ 能夠看到初始化頁面.nginx

其餘命令

須要在nginx根目錄運行.web

nginx.exe -s stop                   //中止nginx

nginx.exe -s reload                //從新加載nginx

nginx.exe -s quit                     //退出nginx

配置

nginx配置文件爲 /conf/nginx.conf api

同時運行兩個web程序

配置兩個server便可. 例子:app

server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }
        location /prod-api{
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:8080/;
        }
    }
    
    server {
        listen       90;
        server_name  localhost;
        location / {
            root   admin_html;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }
        location /prod-api{
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:8080/;
        }        
    }

日誌切分

nginx自身並不可以切分或滾動日誌,所以只能用一個bat腳本按天切割日誌,並刪除三天前的日誌.
將此bat腳本設置定時任務明天0點運行便可:字體

@echo off
rem nginx滾動日誌
rem nginx工做目錄
set workspace=D:\luozixi\nginx-1.16.0
rem 日誌存放目錄
set logdir=D:\luozixi\nginx-1.16.0\logs
rem 將當前日誌重命名,用今日的日期
move %logdir%\access.log %logdir%\access_%date:~0,4%_%date:~5,2%_%date:~8,2%.log
move %logdir%\error.log %logdir%\error_%date:~0,4%_%date:~5,2%_%date:~8,2%.log
rem 從新打開日誌文件,若是不作這一步,nginx會繼續往已被重命名的日誌文件中寫入日誌
%workspace%\nginx.exe -s reopen -p %workspace%
rem 刪除三天前的日誌
set DaysAgo=3
forfiles /p %logdir% /m *.log /d -%DaysAgo% /c "cmd /c del /f /q @path"
pause

原文參考1ui

原文參考2

Flutter 寫的app, 須要源碼能夠私信~~


最好的筆記軟件

https://www.wolai.com/signup?...spa

相關文章
相關標籤/搜索