Install and configure Nginx under Windows, and set it to power on automatically

Keywords: Nginx Windows xml encoding

Installation and configuration of Nginx under Windows

First, Download

Process ellipsis

Two, configuration

First, enter the nginx installation directory (the same level of nginx.exe) and edit the conf/nginx.conf file

   gzip  on; #Open gzip
   server_tokens off; ##Hide nginx version number

   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;  #Target server
           # 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;
       }
3, General startup:

This method can be avoided here. Later, it will be introduced to set the power on self start mode. After the nginx is included in the system service, it will be managed through the system command

  1. start nginx start
  2. nginx -s stop
  3. nginx -s quit stop nginx completely and orderly
  4. nginx -s reopen log file
  5. nginx -s reload reload configuration
4, Set power on self start:

Recommended use Windows Service Wrapper Tools to install self starting services:

1. Download WinSW.NET4.exe; (if the server does not install. NET Framework 4.0, please download WinSW.NET2.exe)
2. Copy WinSW.NET4.exe to the same directory of nginx.exe, and rename it to nginxd.exe;
3. Create a new nginxd.xml configuration file in the same directory of nginxd.exe. The content is as follows:

<?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. Execute nginxd.exe install registration service

winsw Related commands:

  • 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. Start with NET command of windows system

net start nginx start
net stop nginx stop

net related commands:

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

Above.

Posted by mkosmosports on Sun, 09 Feb 2020 06:47:16 -0800