程序员学习互联网科技

Windows下 Nginx安装与配置,设置开机自启

2018-07-19  本文已影响51人  姬艾思

Windows下 Nginx安装与配置

一、下载

过程省略

二、配置

首先进入nginx安装目录(nginx.exe同级),编辑conf/nginx.conf文件

   gzip  on; #开启gzip
   server_tokens off; ##隐藏nginx版本号

   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;  #目标服务器
           # 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;
       }
三、常规启动:

这里可以先不采用此方式,稍后介绍设置开机自启,将nginx纳入系统服务后,通过系统命令管理

  1. start nginx 启动
  2. nginx -s stop 快速停止nginx
  3. nginx -s quit 完整有序的停止nginx
  4. nginx -s reopen 重新打开日志文件
  5. nginx -s reload 重新加载配置
四、设置开机自启:

推荐使用Windows Service Wrapper工具来安装自启动服务:

1.下载WinSW.NET4.exe;(如果服务器未安装.NET Framework 4.0,请下载 WinSW.NET2.exe)
2.将WinSW.NET4.exe拷贝到nginx.exe相同目录下,并重命名为nginxd.exe;
3.在nginxd.exe相同目录下新建一个nginxd.xml的配置文件,内容如下:

<?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.执行nginxd.exe install 注册服务

winsw相关命令:

  • 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系统NET命令启动

net start nginx 启动
net stop nginx 停止

net相关命令:

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

以上。

上一篇下一篇

猜你喜欢

热点阅读