nginx配置(反向代理,ssl...)

1 nginx配置反向代理,负载均衡配置;

upstream qq_com
{
    ip_hash;
    server 127.0.0.1:8080;
    server 127.0.0.1:8081;
}

server
{
    listen 80;
    server_name www.qq.com;

    location /
    {
        proxy_pass      http://qq_com;
        proxy_set_header Host   $host;
        proxy_set_header X-Real-IP      $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

2 nginx 配置SSL

server
{
    listen 443;
    server_name a.com;
    index index.html index.php;
    root /data/nginx/a.com;

     ssl on;
     ssl_certificate   cert/215058855400123.pem;
     ssl_certificate_key  cert/215058855400123.key;
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

     location / {
            root   /home/www/a.com;
            index  index.html index.htm;
        }

    access_log /tmp/1.log combined_realip;
}

3 nginx 配置静态目录


  server {
    listen    8088;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;
    
    location ~ .*\.(gif|jpg|jpeg|png)$ { 
      expires 24h; 
      root usr/local/image/;#指定图片存放路径 
      access_log usr/local/image/images.log;#日志存放路径 
      proxy_store on; 
      proxy_store_access user:rw group:rw all:rw; 
      proxy_temp_path   sr/local/image/;#图片访问路径 
      proxy_redirect   off; 
      proxy_set_header  Host 127.0.0.1; 
      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://127.0.0.1;
      } 
    }

4 nginx 用户认证

server
{
    listen 80;
    server_name test.com;
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    
location  /
    {
        auth_basic              "Auth";
        auth_basic_user_file   /usr/local/nginx/conf/htpasswd;
}
}
 yum install -y httpd
 htpasswd -c /usr/local/conf/htpasswd aming

./nginx -s reload

 

你可能感兴趣的:(运维)