zoukankan      html  css  js  c++  java
  • 学会配置nginx

    一、作为一名开发人员,大家可能经常会用到服务器,但是一般线上的服务器可能都是公司公用的,而且线上的服务器一般也不是能随随便便给个人用的,所以部署本地服务器看来是一遍必不可少的事情和能力呀,所以,nginx腾空而出,它可以在任何一款vim终端配置部署,只要你能配置的好,它就是一款很不错的本地服务器,对你的开发有不小的帮助;

    二、好了,废话不多说,接下来我给大家贴一个自己以往配置过的nginx配置:

    例子1:这个是大而全的例子

    ##运行用户
    #user nobody;
    #启动进程,通常设置程和cpu的数量相等
    worker_processes 1;

    #全局错误日志及PID文件
    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    #pid logs/nginx.pid;

    ##工作模式及连接数上限
    events {
    ####epoll是多路复用IO(I/O Multiplexing)中的一种方式
    #use epoll

    ###单个后台worker process 进程的最大并发链接数
    worker_connections 1024;
    }


    http {
    ###设定mime类型,类型由mime.type文件定义
    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指令指定nginx是否调用sendfile函数(zero copy方式)来输出文件,
    ##对于普通应用,必须设为 on,
    #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
    #以平衡磁盘与网络I/O处理速度,降低系统的uptime.
    sendfile on;
    #tcp_nopush on;
    #连接超时时间
    #keepalive_timeout 0;
    keepalive_timeout 65;

    #开启gzip压缩
    #gzip on;
    #设定虚拟主机配置
    server {
    #侦听80端口
    listen 8080;
    #定义使用 localhost访问
    server_name localhost;

    #charset koi8-r;
    #设定本虚拟主机的访问日志
    #access_log logs/host.access.log main;

    # 定义固定访问的dist目录位置

    location / {
    root /data/projects/one-workflow/frontend/dist;
    index index.html index.htm;
    }

    # 定义后端访问代理的动态接口

    location /api {

    proxy_pass http://ip:8000;
    }

    #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;
    }
    # location / {
    # root /usr/share/nginx/html;
    # index index.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;
    # }
    #}


    # 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;
    # }
    #}
    include servers/*;
    #include vhost/*.conf;
    }

    例子2:这个是比较简化版的例子:

    server {
    server_name 10.10.72.92;
    charset utf-8;

    listen 8001;  ##监听端口是8001

    # Or if running hue on https://
    ## listen 8001 ssl;
    ## ssl_certificate /path/to/ssl/cert;
    ## ssl_certificate_key /path/to/ssl/key;

    location / {
    proxy_pass http://cmdb;

    # Or if the upstream Hue instances are running behind https://
    ## proxy_pass https://hue;
    }

    location /static/ {
    # Uncomment to expose the static file directories.
    ## autoindex on;

    # If Hue was installed with packaging install:
    #alias /data/cloud/deploy/src/hue-4.1.0//build/static/;
    #alias /data/cloud/deploy/src/hue-3.9.0-cdh5.11.0/build/static/;
    alias /data/cloud/deploy/src/funpu_daas_cmdb/static/;

    # Or if on a parcel install:
    ## /opt/cloudera/parcels/CDH/lib/hue/build/static/;

    expires 30d;
    add_header Cache-Control public;
    }

    大家可以根据自己的项目,作相应的改动;

  • 相关阅读:
    Opengl绘制我们的小屋(二)第一人称漫游
    C# this.Invoke和this.BeginInvoke 最简单的写法
    C# 递归模型定义。赋值
    .net Core 2.1 后 Session保存,新页面获取不到值
    .net core mvc 错误信息显示 ModelState.AddModelError
    .net Core 依赖注入 Add********说明
    C# 中2个问号的作用。C#的??代表是什么意思
    asp.net mvc 加三层架构 完美搭配
    C# DataTable.Compute()用法
    C# DateTime判断时间
  • 原文地址:https://www.cnblogs.com/haoxinchen/p/8410312.html
Copyright © 2011-2022 走看看