Nginx command:

Start: start nginx

Stop: stop nginx – s | | nginx -s quit

Note: stop is to stop nginx quickly, and may not save related information; Quit is a complete and orderly stop to nginx and save the information.

View the version: nginx -v

Reload: nginx -s reload

Check the syntax: nginx-t

Steps:

1. Install Windows (I am currently using Windows 7)

Official website download address:Nginx.org/en/download…Download nginx-1.14.2

Decompressed file directory:

Note: all the static resources you need are placed in the HTML folder. Three times more important, when you start nginx, open your static resources locally

Two: Run nginx

As shown, click on the address bar, type CMD, and press Enter

Start nginx: start nginx

Enter localhost will start browsing address bar nginx default HTML page | | in the CMD enter ipconfig for current use the computer’s IP address

As shown above, the startup is successful;

Three: Configure its own service ports

Open the nginx-1.14.2/conf/nginx.conf file

#user nobody;
worker_processes  1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
  worker_connections  1024;
}


http {
  include       mime.types;
  default_type  application/octet-stream;

  #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  # '$status $body_bytes_sent "$http_referer" '
  # '"$http_user_agent" "$http_x_forwarded_for"';

  #access_log logs/access.log main;

  sendfile        on;
  #tcp_nopush on;

  #keepalive_timeout 0;
  keepalive_timeout  65;

  #gzip on;server { listen 9000; Localhost :9000 server_name localhost; localhost:9000 server_name localhost;#charset koi8-r;

      #access_log logs/host.access.log main;

      location / {
          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;
      #}
  }
  server {  # here is my own configuration service port
      listen       8081;
      server_name resouce;
      root  D:/book/resouces;  Access the file root directory
      autoindex on;  Whether to browse the list under the file
      location / {  # Whether cross-domain is allowed
          add_header Access-Control-Allow-Origin *;
      }
      add_header Cache-Control "no-cache,must-revalidate";# cache or not
  }

  # another virtual host using mix of IP-, name-, and port-based configuration
  #
  #server {
  # listen 8000;
  # listen somename:8080;
  # server_name somename alias another.alias;

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


  # HTTPS server
  #
  #server {
  # listen 443 ssl;
  # server_name localhost;

  # ssl_certificate cert.pem;
  # ssl_certificate_key cert.key;

  # ssl_session_cache shared:SSL:1m;
  # ssl_session_timeout 5m;

  # ssl_ciphers HIGH:! aNULL:! MD5;
  # ssl_prefer_server_ciphers on;

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

}
Copy the code

Listen :8081: localhost:8081: localhost:8081: localhost:8081: localhost:8081: localhost:8081

This simple, nginx static resource server is set up successfully;

Here are the problems I encountered:

Nginx-s reload error:

[error] | nginx: [error] invalid PID number "" in"/usr/local/nginx - 1.12.2 / nginx_my. PID"Copy the code

Solution: check in nginx start (open the page to see if I can open the | | using the command nginx -s reopen | | to see if there is a computer process nginx, etc.), the startup and then reload nginx – s;

Nginx -s reload only tells the running nginx process to reload its configuration. After the nginx process stops, no signal is sent from the running nginx process

Reference page: original link

Relatively simple, just as a simple note.