Nginx is running under windows

1. Download nginx

Download the stable version 1.12, here is the download address

http://nginx.org/download/nginx-1.12.2.zip

2, install nginx

Downloaded zip directly decompression, and then double-click nginx.exe, double-click a black pop flashed.

There are local command-line operations after the installation is complete, you need to be in the same directory nginx.exe, the following chart, I was in G: \ under Download \ nginx-1.12.2 directory
Here Insert Picture Description

3, check whether the installation was successful

In the browser address bar enter the URL http: // localhost: 80, carriage return, appear the following screenshot is installed successfully.
Here Insert Picture Description

If you visit http: // localhost: 80 when out of iis page,
you need to enter net stop w3svc end of the run iis in cmd inside, and then re-visit http: // localhost: 80
If there are other services take up 80 ports available in the conf directory nginx.conf the port 80 into the inside of the other figures
Here Insert Picture Description

4, close nginx

Both methods

(1)输入nginx命令  nginx -s stop(快速停止nginx) 或 nginx -s quit(完整有序的停止nginx)

(2)使用taskkill   taskkill /f /t /im nginx.exe

5, abnormal reboot

Here Insert Picture Description
If this abnormal system task manager you can find nginx.exe process, kill it, or find the time to look carefully to find, probably in the following command handler, which may also appear in the background process are killed like
Here Insert Picture Description

5.1, try to run

5.1.1, shutdown and restart

First check how many nginx is running (you can see in this screenshot only one run)
Here Insert Picture Description

 netstat -an|find "0:80"

If there are multiple, can be closed (the following two commands may be closed)

nginx -s stop         快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。
nginx -s quit         平稳关闭Nginx,保存相关信息,有安排的结束web服务。

Restart

start nginx

Browser, enter http: // localhost / you the following interface for success
Here Insert Picture Description

5.1.2, modify the configuration file, try running your own html
在进行这一步之前你可能会遇到其他错误,如果不是因为你修改了某些配置文件造成的,
那可能是因为有多个nginx进程同时在运行,并占用了同一端口,你可以先把它们都杀掉,
然后重新启动,具体参考本文 ‘ 5、重启时出现异常 ’

The configuration file is nginx.conf files in the conf directory
Here Insert Picture Description
where I put the original nginx.conf a backup, and then modified into the following:


#user  nobody;
worker_processes  1;
events {
    worker_connections  1024;
}


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

    sendfile        on;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   G:/Download/nginx-1.12.2/test;
            index  index.html index.htm;
        }

    }

}

G here: /Download/nginx-1.12.2/test I used to test the html directory,
the directory here remember to use / instead of \, otherwise an error
Here Insert Picture Description
Here Insert Picture Description
index.html (there must be a name index.htm , remember that if you want to change the index in the back configuration file, directory, and file name into the corresponding)

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>

<h1>我的第一个标题</h1>
<p>我的第一个段落。</p>

</body>
</html>

Browser to access http: // localhost /
Here Insert Picture Description

Try to run successfully

6, the windows running nginx easy to step pit

  • nginx is to adapt to this environment to run linux,
  • linux on paths / distinction under a directory,
    Windows with \ distinguished under a directory,
  • So when you run nginx, conf files which have changed with the best path absolute path, and with / to distinguish the next level directory,
    Here Insert Picture DescriptionHere Insert Picture Description
    as few places should be written as absolute path, or it may be an error (at run time of the test conf probably does not complain, but when you change the path may run conf on the error)
 比如这里的
 include       mime.types;
 
 最好写成   (注意: G:/Download/nginx-1.12.2/conf/  是我的mime.types所在目录,你应该换成你的mime.types所在目录)
 include       G:/Download/nginx-1.12.2/conf/mime.types;

Appears The system can not find the file specified path is probably / and \ caused

Here Insert Picture Description

Published 87 original articles · won praise 20 · views 1615

Guess you like

Origin blog.csdn.net/a__int__/article/details/103897237
Recommended