美文网首页
Window环境下搭建Nginx服务器

Window环境下搭建Nginx服务器

作者: WebProgress | 来源:发表于2020-02-11 22:39 被阅读0次

一、Nginx简介

Nginx是一款轻量级Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东新浪网易腾讯淘宝等。
Nginx 是一个安装非常的简单、配置文件非常简洁(还能够支持perl语法)、Bug非常少的服务。Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。

二、Nginx下载

Windows环境版本下载压缩包:http://nginx.org/en/download.html

三、启动与配置

Nginx压缩包进行解压,如图:

Nginx压缩包文件
conf:是存放Nginx的配置文件;
contrib:存放其他组织贡献的代码;
docs:存放Nginx的一些文档;
html:存放Nginx的默认网页;
logs:存放Nginx的日志信息;
temp:存放一些临时文件;
nginx.exe:Nginx的启动文件;

配置文件:\nginx-1.16.1\conf\nginx.conf

    server {
        listen       8087;#默认端口80,此处修改为8087
        server_name  localhost;#服务器名称,可以配置域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #启动路径配置:默认/;比如启动:http://localhost:8089/
        location / {
            root   html;#资源路径,默认在/html文件夹下
            index  index.html index.htm;#启动首页
        }
        #404错误页面
        #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;
        #}
    }

默认的文件夹下:/html

Nginx默认启动页html文件夹

双击nginx.exe运行,一闪而过;如果启动成功,在浏览器输入:http://localhost:8087会打开默认的/html/index.html网页:

Nginx启动成功页面

三、访问图片与其它文件

Nginx默认配置的文件夹路径是html,启动后打开了默认的index.html,所以最简单的文件配置访问方式是把资源文件直接放到html文件夹下,此处在html文件夹下创建了存放图片的images文件夹,并存放了一个图片,访问路径:http://localhost:8087/images/图片全名称
实例如图:

访问图片实例

四、Nginx官方文档

http://nginx.org/en/docs/

五、鼓励一下

写作不易,有帮助就赞一下呗!

相关文章

网友评论

      本文标题:Window环境下搭建Nginx服务器

      本文链接:https://www.haomeiwen.com/subject/jieffhtx.html