Windows下 Nginx安裝與配置,設(shè)置開機(jī)自啟

Windows下 Nginx安裝與配置

一、下載

過程省略

二、配置

首先進(jìn)入nginx安裝目錄(nginx.exe同級(jí)),編輯conf/nginx.conf文件

   gzip  on; #開啟gzip
   server_tokens off; ##隱藏nginx版本號(hào)

   server {
       listen       8888;
       server_name  localhost;
       charset utf-8;  
       #charset koi8-r;

       #access_log  logs/host.access.log  main;

       location / {
           root   html/dist/;
           index  index.html index.htm;
       }

       location /oms {
           proxy_pass   http:ip:port;  #目標(biāo)服務(wù)器
           # proxy_set_header   Host             $host;
           # proxy_set_header   X-Real-IP        $remote_addr;
           # proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
           # proxy_set_header   X-Forwarded-Proto  $scheme;
       }
       #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;
       }
三、常規(guī)啟動(dòng):

這里可以先不采用此方式,稍后介紹設(shè)置開機(jī)自啟,將nginx納入系統(tǒng)服務(wù)后,通過系統(tǒng)命令管理

  1. start nginx 啟動(dòng)
  2. nginx -s stop 快速停止nginx
  3. nginx -s quit 完整有序的停止nginx
  4. nginx -s reopen 重新打開日志文件
  5. nginx -s reload 重新加載配置
四、設(shè)置開機(jī)自啟:

推薦使用Windows Service Wrapper工具來安裝自啟動(dòng)服務(wù):

1.下載WinSW.NET4.exe;(如果服務(wù)器未安裝.NET Framework 4.0,請(qǐng)下載 WinSW.NET2.exe)
2.將WinSW.NET4.exe拷貝到nginx.exe相同目錄下,并重命名為nginxd.exe;
3.在nginxd.exe相同目錄下新建一個(gè)nginxd.xml的配置文件,內(nèi)容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<service>
  <id>nginx</id>
  <name>nginx</name>
  <description>nginx</description>
  <executable>D:\softs\nginx-1.14.0\nginx.exe</executable>
  <startargument>-p</startargument>
  <startargument>D:\softs\nginx-1.14.0</startargument>  
  <logpath>D:\softs\nginx-1.14.0/logs</logpath>
  <logmode>roll</logmode>  
  <stopexecutable>D:\softs\nginx-1.14.0\nginx.exe</stopexecutable>
  <stopargument>-p</stopargument>
  <stopargument>D:\softs\nginx-1.14.0</stopargument>
  <stopargument>-s</stopargument>
  <stopargument>stop</stopargument>
  <stoptimeout>6sec</stoptimeout>
</service>

4.執(zhí)行nginxd.exe install 注冊(cè)服務(wù)

winsw相關(guān)命令:

  • install to install the service to Windows Service Controller. This command requires some preliminary steps described in the Installation Guide.
  • uninstall to uninstall the service. The opposite operation of above.
  • start to start the service. The service must have already been installed.
  • stop to stop the service.
  • restart to restart the service. If the service is not currently running, this command acts like start.
  • status to check the current status of the service.
    This command prints one line to the console.
    NonExistent indicates the service is not currently installed
    Started to indicate the service is currently running
    Stopped to indicate that the service is installed but not currently running.

5.通過windows系統(tǒng)NET命令啟動(dòng)

net start nginx 啟動(dòng)
net stop nginx 停止

net相關(guān)命令:

NET
   [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |
     HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START |
     STATISTICS | STOP | TIME | USE | USER | VIEW ]

以上。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容