官网地址
当前最新版本是nginx/Windows-1.17.9,所以我就选择nginx/Windows-1.17.9
版本的下载的了。你可以根据个人的选择下载不同的版本
C:\nginx-1.17.9
├─conf
│ fastcgi.conf
│ fastcgi_params
│ koi-utf
│ koi-win
│ mime.types
│ nginx.conf
│ scgi_params
│ uwsgi_params
│ win-utf
├─contrib
├─docs
├─html
│ 50x.html
│ index.html
├─logs
├─temp
└ nginx.exe
这里只是列举了等下需要用到的文件夹以及子文件夹。 nginx -v
start nginx
nginx -s reload
nginx -s stop
nginx -s quit
以上是命令行操作启动方式。
windows系统上,你想启动nginx服务的话,还可以这么做。
说明:
官方文档有如下说明:
nginx/Windows runs as a standard console application (not a service), and it can be managed using the following commands:
意思是说:nginx / Windows作为标准控制台应用程序(不是服务)运行,可以使用以下命令进行管理:
nginx -s stop fast shutdown
nginx -s quit graceful shutdown
nginx -s reload changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes
nginx -s reopen re-opening log files
nginx -s停止 快速关机
Nginx -s退出 正常关机
nginx -s重新加载 更改配置,使用新配置启动新工作进程,正常关闭旧工作进程
nginx -s重新打开 重新打开日志文件
它是作为一个标准程序启动的,所以每次启动电脑,你要手动启动该应用,它才会为你提供服务。
就是每次重启电脑都要重新启动下nginx服务的。如有需要配置开机自启,请关注我的后面的博客。
启动了nginx之后,在浏览器里面输入localhost
,出现如下的提示,就证明配置成功了,而且可以正常使用了。
上面目录结构图的时候,有展示到一个html目录,这个就是运行网站默认的根目录。这个nginx配置的默认目录。
如果你只是简单的调试页面话,可以直接在这个目录内操作。
nginx的配置文件在软件目录下的./conf/nginx.conf
,这个目录在上面的目录结构也有体现。
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
这段就是nginx给你的默认配置。我们看到,它监听的是80端口,root目录为html,自动识别的文件有index index.html index.htm;
这样的几种。
该配置文件的下面有个实例配置,被注释了。 配置自己的监听,可以参考这个。
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
下面我配置一个监听域名为:blog.test,端口也是80端口的配置:
# 监听本地域名为blog.test,端口为80
server {
listen 80;
server_name blog.test;
location / {
root C:\WWW\blog;
index index.html index.htm;
}
}
我的网站根目录在C:\WWW\blog
,里面有一个index.html
文件。改动之后记得重新加载配置:
nginx -s reload
在浏览器输入http://blog.test
出现如下页面:
配置成功了
注意:换了自己的域名后,需要在系统的host文件中配置该域名指向本地的
原文:https://www.cnblogs.com/hxsen/p/12688560.html