nginx的详细配置

nginx的详细配置

1 配置虚拟主机

就是在一台服务器启动多个网站。

如何区分不同的网站:主要有以下两种方式

方式一:端口不同

方式二:域名不同

2 通过端口区分不同的主机和多个域名区分虚拟主机

nginx配置文件的位置:/usr/local/nginx/conf/nginx.conf

原始配置文件的内容如下:

 


#user  nobody;
worker_processes  1;

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  127.0.0.1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   404 500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }


    upstream  server2  {
	server  127.0.0.1:7200;
    }

    server {
        listen       80;
        server_name  域名;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
	    proxy_pass  http://server2;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   400 404 500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    upstream  server3  {
	server  127.0.0.1:7900;
    }

    server {
        listen       80;
        server_name  域名;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
	    proxy_pass  http://server3;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   400 404 500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }



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



   upstream  server1  {
	server  127.0.0.1:7900;
    }


    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  域名;

        ssl_certificate      /usr/local/nginx/ssl/3481578.pem;
        ssl_certificate_key  /usr/local/nginx/ssl/3481578.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

	ssl_ciphers  ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers  on;

        location / {
	    proxy_pass  http://server1;
            proxy_redirect  off;
            default_type  application/json;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  Host $http_host;
            client_max_body_size   25m;
        }

	location /files {
             add_header   'Access-Control-Allow-Origin' '*';
              alias   /usr/local/network/nw-static-file/file;
        }
    }

}

这里面还包括了https域名的配置

 

3 正向代理

 

4 反向代理

 

 

 

 

5 负载均衡

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值