docker-compose 配置 nginx

nginx 目录结构

- conf
- conf.d
- logs
- proxy_temp
- run
- docker-compose.yml

docker-compose.yml

version: '3.7'
services:
    nginx :
        container_name : v-nginx
        image: nginx:1.13
        restart: always
        ports:
            - 80:80
            - 443:443
        volumes:
            - ./conf/nginx.conf:/etc/nginx/nginx.conf
            - ./conf.d:/etc/nginx/conf.d/
            - ./logs:/var/log/nginx/
            - ./run:/run/
            - ./proxy_temp:/usr/local/nginx/proxy_temp
            - /opt/static:/opt/static

conf/nginx.conf

user  nginx;
worker_processes  1;
 
error_log  /var/log/nginx/error.log warn;
pid        /run/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"';

    log_format  ap   '$remote_addr - $remote_user [$time_local] "$request" '
          '$status $body_bytes_sent "$http_referer" '
          '"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio" "$ssl_protocol $ssl_cipher" '
          '"Cache-Control: $upstream_cache_status $upstream_http_cache_control" "$http_ua_uuid"';
 
    access_log  /var/log/nginx/access.log  main;
    sendfile           on;#开启高效文件传输模式  
    keepalive_timeout  65;#长连接超时时间,单位是秒   
          
    tcp_nopush   on;#防止网络阻塞 
    tcp_nodelay  on;#防止网络阻塞 
    server_names_hash_bucket_size 128;#服务器名字的hash表大小 
    client_header_buffer_size 32k;#上传文件大小限制 
    large_client_header_buffers 4 32k;#设定请求缓存 
    client_max_body_size  600m;#设定请求緩存 
    client_body_buffer_size  128k;     


    # gzip 压缩功能设置  
    gzip on;#开启gzip压缩输出
    gzip_static on;
    gzip_min_length 1k;#最小压缩文件大小  
    gzip_buffers 4 16k;#压缩缓冲区   
    gzip_http_version 1.1;#压缩版本(默认1.1,前端如果是squid2.5请使用1.0)  
    gzip_comp_level 6;#压缩等级 
    gzip_types text/plain text/css application/json application/javascript application/x-javascript application/xml;   
    #压缩类型,默认就已经包含text/html,所以就不用再写了,写上去也不会有问题,但是会有一个warn  
    gzip_vary on;#开启限制IP连接数的时候需要使用
#    gzip_disable "MSIE [1-6]\.(?!.*SV1)";    
    gzip_disable "MSIE [1-6]."


    #http_proxy 设置    
    proxy_connect_timeout  75;    
    proxy_send_timeout  75;    
    proxy_read_timeout  75;    
    proxy_buffer_size  16k;    
    proxy_buffers  4 32k;    
    proxy_busy_buffers_size  64k;    
    proxy_temp_file_write_size  64k;    
    proxy_temp_path  /usr/local/nginx/proxy_temp 1 2;
 
    include /etc/nginx/conf.d/*.conf;
}

conf.d/xqghp.com.conf

upstream tomcat_20120 {
#   server 127.0.0.1:20120;
   server 172.17.0.1:20120;
}

server {
   listen       80;
   server_name  xqghp.com www.xqghp.com;
   return      301 https://$server_name$request_uri;      #http重定向到https,这是nginx最新支持的写法
   #rewrite ^(.*) https://$server_name$1 permanent;
}

server {
    listen 443 ssl;
    server_name xqghp.com www.xqghp.com;

#    charset utf-8;
#    access_log off;

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

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


    location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
        root /opt/static;
        #expires定义用户浏览器缓存的时间为7天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
#        expires      7d;
        expires -1;
    }

    location /img/ {
        root    /opt/static;
    }     

    ssl_certificate /etc/nginx/conf.d/ssl/xqghp.com.pem;
    ssl_certificate_key /etc/nginx/conf.d/ssl/xqghp.com.key;
    # Enables all versions of TLS, but not SSLv2 or 3 which are weak and now deprecated.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access_manage.log main;
}

conf.d/calc.ink.conf

upstream tomcat_20130 {
   server 172.17.0.1:20130;
}

server {
   listen       80;
   server_name  calc.ink www.calc.ink;
   return      301 https://$server_name$request_uri;      #http重定向到https,这是nginx最新支持的写法
   #rewrite ^(.*) https://$server_name$1 permanent;
}

server {
    listen 443 ssl;
    server_name calc.ink www.calc.ink;

#    charset utf-8;
#    access_log off;

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

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


    location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
        root /opt/static;
        #expires定义用户浏览器缓存的时间为7天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
#        expires      7d;
        expires -1;
    }

    location /img/ {
        root    /opt/static;
    }     

    ssl_certificate /etc/nginx/conf.d/ssl/calc.ink.pem;
    ssl_certificate_key /etc/nginx/conf.d/ssl/calc.ink.key;
    # Enables all versions of TLS, but not SSLv2 or 3 which are weak and now deprecated.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access_manage.log main;
}

conf.d/pha.xqghp.com.conf

server {
    listen 80;
    server_name pha.xqghp.com;
    root        /opt/workspace/pha/phabricator/webroot; # 配置根目录

    location / {
        index index.php;
        rewrite ^/(.*)$ /index.php?__path__=/$1 last;
    }

    location /index.php {
        fastcgi_pass    unix:/run/php/php7.3-fpm.sock;
        fastcgi_index   index.php;

     	#required if PHP was built with --enable-force-cgi-redirect
    	fastcgi_param  REDIRECT_STATUS    200;

	    #variables to make the $_SERVER populate in PHP
	    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    	fastcgi_param  QUERY_STRING       $query_string;
    	fastcgi_param  REQUEST_METHOD     $request_method;
	    fastcgi_param  CONTENT_TYPE       $content_type;
    	fastcgi_param  CONTENT_LENGTH     $content_length;

	    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

	    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
	    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

    	fastcgi_param  REMOTE_ADDR        $remote_addr;
    }

    access_log /var/log/nginx/access_manage.log main;
}
  • qq_43638135
    妲己再美究为妃: 博主没有想过自己接一些私活干吗?我现在还没毕业,但是我也确实听说外挂市场自动化游戏脚本市场挺火热的,并且报酬也很丰厚,但是具体的我也不是很清楚,求解答。 (1个月前 #47楼) 查看回复(2) 举报 回复
    22