nginx配置样例

简单的nginx配置如下,包含了静态文件配置、websocket、socket.io的配置:

user nobody;
worker_processes  3;
#master_process off;
#daemon off;
#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;

    client_max_body_size 1024m;
    client_body_buffer_size 1m;
    sendfile        on;
    #tcp_nopush     on;
    gzip on;
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    upstream bcWebServer {  
        server 127.0.0.1:8360;
    }



    server {
      listen       80;
      server_name  localhost;

      #charset koi8-r;

      #access_log  logs/host.access.log  main;
                      proxy_set_header  X-real-ip $remote_addr;
      location / {
              root /opt/bstar/html;    # bcweb前台静态文件放置的目录
              #root  /usr/local/nginx/html;
              index  index.html index.htm;
      }

      location /api/local{
              proxy_pass                  http://bcWebServer;
      }

      location /api/bc{
              proxy_pass                  http://bcWebServer;
      }
      
      location /api/render{
              proxy_pass                  http://bcWebServer;
      }
                  
      #location /api/log{
      #        auth_url "/auth";
      #        proxy_pass                  http://LoginServer;
      #}
      
      #location /auth{
      #        proxy_pass                  http://authServer;
      #}

      #location /api/ws/alarm {
      #        proxy_pass http://AlarmWebSocket;
      #        proxy_http_version 1.1;
      #        proxy_set_header Upgrade $http_upgrade;
      #        proxy_set_header Connection "upgrade";
      #}

      location /socket.io {
             proxy_pass  http://127.0.0.1:8360;
             proxy_redirect off;
             proxy_set_header Host $http_host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             # socket.io
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection "upgrade";
      }

      location /api {
              proxy_set_header   X-Real-IP $remote_addr;
              proxy_set_header   Host      $http_host;
              # change this to your server host
              proxy_pass         http://127.0.0.1:8360;
      }

      location ~ .*\.(gif|jpg|jpeg|png)$ {  
            expires 24h;  
            #root /usr/local/nginx/html;#指定图片存放路径  
            root /opt/bstar/html;
            access_log /home/images.log;#日志存放路径
            proxy_store on;  
            proxy_store_access user:rw group:rw all:rw;  
            proxy_temp_path     /usr/local/nginx/images/;#图片访问路径  
            proxy_redirect     off;  
            proxy_set_header    Host 192.168.20.39;  
            client_max_body_size  10m;  
            client_body_buffer_size 1280k;  
            proxy_connect_timeout  900;  
            proxy_send_timeout   900;  
            proxy_read_timeout   900;  
            proxy_buffer_size    40k;  
            proxy_buffers      40 320k;  
            proxy_busy_buffers_size 640k;  
            proxy_temp_file_write_size 640k;  
            if ( !-e $request_filename)  
            {  
               proxy_pass http://192.168.20.39;#默认80端口  
            }  
      }

        #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 192.168.8.147:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://192.168.8.147;
        #}

        # pass the PHP scripts to FastCGI server listening on 192.168.8.147:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   192.168.8.147: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;
    #    }
    #}

}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏从零开始学自动化测试

Fiddler抓包11-HTTPS证书Actions无法导出问题

前言 在点Actions时候出现Export Failed:The root certificate could not be located.最近有很多小伙伴...

2525
来自专栏玩转JavaEE

Git工作区储藏兼谈分支管理中的一个小问题

这是一篇计划之外的文章,之所以有这篇文章,是因为有一个小伙伴在阅读Git分支管理一文时遇到了一个问题,而这个问题又比较典型,因此我想专门来谈谈Git中工作区的储...

2785
来自专栏Android点滴积累

ADB server didn't ACK

[2015-05-29 11:55:03 - adb] ADB server didn't ACK [2015-05-29 11:55:03 - adb] * ...

1996
来自专栏散尽浮华

Linux下squid代理缓存服务环境部署

代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息。 Squid是一个缓存Internet 数据的软件,其接收用户的下载申请,并...

20410
来自专栏静下来

CDN加速下通过nginx获取网站访客真实ip

image.png 我们官网后台有访客防火墙,为了统计用户的登录信息,由于网站做了全站的CDN,所以防火墙默认获取到的ip全是CDN的ip。 这样就不便于我们...

3886
来自专栏性能与架构

Web安全 - 跨站请求伪造攻击CSRF

跨站请求伪造攻击,简称CSRF(Cross-site request forgery),CSRF通过伪装来自受信任用户的请求实现攻击 CSRF的原理 CSRF主...

3367
来自专栏云计算教程系列

如何创建自签名证书

TLS/SSL是用于将正常流量包装在受保护的加密包装中的Web协议。得益于此技术,服务器可以在服务器和客户端之间安全地发送流量,而不会被外部各方拦截。证书系统还...

1074
来自专栏运维小白

7.6 yum更换国内源

更换yum国内源 cd /etc/yum.repos.d/ rm -f dvd.repo wget http://mirrors.163.com/.help/C...

2486
来自专栏Java技术栈

jmap, jhat, jvisualvm:java堆内存对象分析利器

jmap -help查看命令用法。 jmap -heap <pid> 查看堆使用情况。 jmap -dump导出堆对象文件进行内存分析。 jhat -J-Xm...

3346
来自专栏运维小白

vmware workstation无法获取IP

有时在安装好虚拟机后,dhclient会发现无法获取IP地址 原因,有可能是连接网络模式的冲突——>个人推测 解决办法: 这时候只需删除桥接模...

17310

扫码关注云+社区