在本地nginx部署测试报错直接上图:

D:\Program Files\nginx-1.20.2\conf\nginx.conf 配置文件:

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
   
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
		default_type  text/html;
	
		location / {
            root   D:/Program Files/nginx-1.20.2/;   ## nginx本地安装路径,斜杠使用 '/' ..
            index  index1.html index1.htm;
		}
             
    }

}

产生错误的原因是  D:/Program Files/nginx-1.20.2/ 中间有空格,正确的应该是 D:/ProgramFiles/nginx-1.20.2/(然而这个也不能用,虽然不报错,但后面文件会找不到),这里替换成  D:/nginxtest/; 修改后再次启动

location / {
      root   D:/nginxtest/;   ## nginx本地安装路径,斜杠使用 '/' ..
      index  index1.html index1.htm;
}

结果:访问图片ok..

总结: 配置目录中不能有中文、空格,ps:最后面的 ‘/’ 不要忘了

最后自己记录下windows下启动、重启、停止nginx
打开cmd 进入到nginx的安装目录下

1.启动nginx:

   start nginx 或 nginx.exe

2.停止nginx(stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息)

  nginx.exe  -s stop 或 nginx.exe -s quit

3.检查 重启:

   nginx -t  修改nginx配置后执行检查配置是否正确
   nginx -s reload 重启
 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐