当前位置: 首页 > news >正文

windows下面nginx配置及测试

1)下载解压

目录是:E:\tools\nginx-1.26.3

2)在E:\tools\nginx-1.26.3下面建目录website

放置index2.html

内容如下 :

<!DOCTYPE html> 
<html> 
<head>
    <title>My Personal Website</title> 
	<meta charset="UTF-8"/>
</head> 
<body>          
    <h1>Welcome to My Personal Website,测试成果,2025.03.23</h1>  
    <p>Here you can learn more about me and my work.</p> 
</body> 
</html>

<meta charset="UTF-8"/>是支持中文用的,或者html网页会出现乱码。

3)目前目录如下

3)修改conf/nginx.conf

内容如下:


#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       80;
        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;
        #}
    }


    # 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;
    #    }
    #}
	
 #虚拟主机2,可以同时配置多个虚拟主机
	 server{
	  listen       8080;
	  server_name  localhost;
	  location / {
		 root   website;
		 index  index2.html index.htm;
	  }
	 }
	 
	  #虚拟主机2,可以同时配置多个虚拟主机


    # 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;
    #    }
    #}

}

其实只是在原始的文件里面添加这个:

 #虚拟主机2,可以同时配置多个虚拟主机
     server{
      listen       8080;
      server_name  localhost;
      location / {
         root   website;
         index  index2.html index.htm;
      }
     }

表示8080端口。

指向的目录是root website,我测试时使用root E:\tools\nginx-1.26.3\website的绝对路径会出错。

4)双击nginx.exe

5)打开任务管理器中

可以看到nginx.exe的进程。

如果出错,直接在任务管理器中杀掉nginx.exe进程,然后再双击nginx.exe

6)查看localhost

7)测试localhost:8080,

都成功了。

相关文章:

  • 网络安全之vlan实验
  • 接口/UI自动化面试题
  • Springboot整合elasticsearch详解 封装模版 仓库方法 如何在linux里安装elasticsearch
  • 八股——Mysql篇
  • WebAssembly实践,性能也有局限性
  • 小白工具PDF转换 PDF转图片 超便捷软件 文件格式转换 简单好用效率高
  • 新手村:逻辑回归-理解04:熵是什么?
  • 第五天 开始Unity Shader的学习之旅之Unity中的基础光照之漫反射光照模型
  • 座舱网联融合新旗舰!移远通信48 TOPS座舱方案携AI大模型能力,赋能多域融合
  • LabVIEW时间触发协议
  • husky的简介以及如果想要放飞自我的解决方案
  • CCF-GESP 等级考试 2025年3月认证C++一级真题解析
  • 一文解读DeepSeek在工业制造领域的应用
  • Win32 / C++ ini配置文件解析类(支持简易加解密)
  • 线性代数核心概念与NumPy科学计算实战全解析
  • 鸿蒙学习笔记(1)-文件解读、编写程序、生命周期
  • 汽车高级驾驶辅助系统应用存储MRAM
  • 边缘计算场景下的分布式推理系统架构设计
  • MySQL索引优化最佳实践
  • Python 3.8 Requests 爬虫教程(2025最新版)
  • 网站后台日志/广安seo外包
  • 临沂网站建设服务/企业网络规划设计方案
  • 网站开发策划个人简历/成都seo网络优化公司
  • 国外 网站 模板/互联网去哪里学
  • 360怎么做网站排名/清远今日头条最新消息
  • 邯郸企业网站制作/贴吧aso优化贴吧