nginx

nginx是一个反向代理服务器。
反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个服务器。

下载地址: http://nginx.org/en/download....

启动: cmd -> d: -> cd tools/nginx -> start nginx
访问 http://localhost / http://127.0.0.1/

配置文件 nginx/conf/nginx.conf
listen: 表示当前的代理服务器监听的端口,默认的是监听80端口
server_name: 表示监听到之后需要转到哪里去,这时我们直接转到本地,这时是直接到nginx文件夹内。
location: 表示匹配的路径,这时配置了/表示所有请求都被匹配到这里
root: 里面配置了root这时表示当匹配这个请求的路径时,将会在这个文件夹内寻找相应的文件
默认为html下 添加路径例子:root html/www/;
index: 当没有指定主页时,默认会选择这个指定的文件,它可以有多个,并按顺序来加载

命令:
查看版本:nginx -v
启动nginx: start nginx
停止nginx: nginx -s stop
优雅停止nginx: nginx -s quit
重新加载配置文件: nginx -s reload
检查配置文件是否有错: nginx -t
杀死主进程:kill -s QUIT 1628 (1628为进程ID、默认路径为/nginx/logs)

前端路由history模式下,nginx配置后404找不到问题解决方式:

    location / {
        root   html;
         if (!-e $request_filename){
              rewrite  ^/  /index.html;
        }
        index  index.html index.htm;
    }

多级目录访问:

// 根
    location / {
        root   html/www/;
        if (!-e $request_filename){
              rewrite  ^/  /index.html;
        }
        index  index.html index.htm;
    }
//二级目录 /w
    location /w {
        alias html/w/;

        index  index.html index.htm;
    }

评论

暂无评论