美文网首页让前端飞
node nignx代理 静态资源处理

node nignx代理 静态资源处理

作者: aHu415 | 来源:发表于2017-12-05 16:28 被阅读0次

    nignx相关的基本操作(mac下)

    1.nignx 当前启动的 配置文件路径查找:命令    nginx -t  

    图1

    2.nignx 安装路径查找:命令  ps  -ef | grep nginx

    如下图2: master process 后面就是 安装目录。如(/usr/local/Cellar/nginx/1.12.1/bin/nginx)

    图2

    3.ningx 安装启动,关闭 及重启。

    安装
    用brew 安装:命令sudo brew install nginx

    启动:
    1.用brew:命令sudo brew services start nginx
    2.寻找默认安装目录:命令  nginx -h

    nginx version: nginx/1.12.1
    Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
    Options:
    -?,-h: this help
    -v: show version and exit
    -V: show version and configure options then exit
    -t: test configuration and exit
    -T: test configuration, dump it and exit
    -q: suppress non-error messages during configuration testing
    -s signal: send signal to a master process: stop, quit, reopen, reload
    -p prefix: set prefix path (default: /usr/local/Cellar/nginx/1.12.1/)
    -c filename: set configuration file (default: /usr/local/etc/nginx/nginx.conf)
    -g directives : set global directives out of configuration file

    /usr/local/Cellar/nginx/1.12.1/ 为默认安装目录
    /usr/local/etc/nginx/nginx.conf 为默认配置文件

    启动:
    /usr/local/Cellar/nginx/1.12.1/bin/nginx -c /usr/local/etc/nginx/nginx.conf

    关闭:命令 pkill nginx

    强制关闭 :命令 sudo pkill -9 nginx

    重启:
        1.kill -HUP 主进程
                如上图2: 命令  kill -HUP 12531
        2. nginx -s reload
           常用命令如下

    nginx                                                #启动nginx
    nginx -s quit                                     #快速停止
    nginx nginx -V                                  #查看版本,以及配置文件地址
    nginx -v                                            #查看版本
    nginx -s reload|reopen|stop|quit      #重新加载配置|重启|快速停止|安全关闭
    nginx -h                                  #帮助

    node nignx代理 静态资源处理 

    注:配置文件路径:/usr/local/etc/nginx/nginx.conf 。修改如下


    1.location ~ ^/public/*  此配置 [public 自定义 拦截Url里/public  指定到指定目录下]
        http://localhost:8080/public/index.html
                会访问/Users/ahu/WebstormProjects/node/ 目录下的  index.html
        http://localhost:8080/public/test/test.html
            会访问/Users/ahu/WebstormProjects/node/test/ 目录下的  test.html

    2.location /此配置是
        nignx 反响代理  node 服务http://127.0.0.1:3001
        访问地址为http://localhost:8080

    server {

    listen      8080;

    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location ~ ^/public/* {

    root /Users/ahu/WebstormProjects/node;

    access_log off;

    expires max;

    }

    location / {

    proxy_pass    http://127.0.0.1:3001;

    proxy_http_version 1.1;

    proxy_set_header Upgrade $http_upgrade;

    proxy_set_header Connection "upgrade";

    proxy_connect_timeout 1;

    proxy_send_timeout 30;

    proxy_read_timeout 60;

    proxy_set_header Host $host;

    }

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

    #}

    }

    相关文章

      网友评论

        本文标题:node nignx代理 静态资源处理

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