<commit_before>package com.ctrip.zeus.service.build.conf;

import com.ctrip.zeus.model.entity.Slb;
import com.ctrip.zeus.util.StringFormat;
import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;

/**
 * @author:xingchaowang
 * @date: 3/8/2015.
 */
public class NginxConf {
    private static DynamicIntProperty nginxStatusPort = DynamicPropertyFactory.getInstance().getIntProperty("slb.nginx.status-port", 10001);
    private static DynamicStringProperty logFormat = DynamicPropertyFactory.getInstance().getStringProperty("slb.nginx.log-format",
            "log_format main '[$time_local] $host $hostname $server_addr $request_method $uri '\n" +
                    "'\"$query_string\" $server_port $remote_user $remote_addr $http_x_forwarded_for '\n" +
                    "'$server_protocol \"$http_user_agent\" \"$cookie_COOKIE\" \"$http_referer\" '\n" +
                    "'$host $status $body_bytes_sent $request_time $upstream_response_time '\n" +
                    "'$upstream_addr $upstream_status';\n"
    );


    public static String generate(Slb slb) {
        StringBuilder b = new StringBuilder(1024);

//        Integer worker = slb.getNginxWorkerProcesses();

//        b.append("worker_processes ").append((worker==null||worker==0)?DEFAULT_WORKERS:worker).append(";\n");
        b.append("worker_processes auto;\n")
         .append("user nobody;\n")
         .append("error_log /opt/logs/nginx/error.log;\n")
         .append("worker_rlimit_nofile 65535;\n")
         .append("pid logs/nginx.pid;\n");


        b.append("events {\n")
         .append("worker_connections 30720;\n")
         .append("use epoll; \n")
         .append("}\n");

        b.append("http {\n");
        b.append("include    mime.types;\n");
        b.append("default_type    application/octet-stream;\n");
        b.append("keepalive_timeout    65;\n");
        b.append(logFormat.get());
        b.append(statusConf());
        b.append("include    upstreams/*.conf;\n");
        b.append("include    vhosts/*.conf;\n");
        b.append("}\n");

        return StringFormat.format(b.toString());
    }

    //slb check health
    private static String statusConf()
    {
        StringBuilder b = new StringBuilder(128);
        b.append("server {").append("\n");
        b.append("listen    ").append(String.valueOf(nginxStatusPort.get())).append(";\n");


        b.append("location / {").append("\n");
        b.append("add_header Access-Control-Allow-Origin *").append(";\n");
        b.append("check_status").append(";\n");
        b.append("}").append("\n");


        b.append("location =/status.json {").append("\n");
        b.append("add_header Access-Control-Allow-Origin *").append(";\n");
        b.append("check_status json").append(";\n");
        b.append("}").append("\n");<commit_msg>fix config change error<commit_after>package com.ctrip.zeus.service.build.conf;

import com.ctrip.zeus.model.entity.Slb;
import com.ctrip.zeus.util.StringFormat;
import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;

/**
 * @author:xingchaowang
 * @date: 3/8/2015.
 */
public class NginxConf {
    private static DynamicIntProperty nginxStatusPort = DynamicPropertyFactory.getInstance().getIntProperty("slb.nginx.status-port", 10001);
    private static DynamicStringProperty logFormat = DynamicPropertyFactory.getInstance().getStringProperty("slb.nginx.log-format",
            "log_format main '[$time_local] $host $hostname $server_addr $request_method $uri '\n" +
                    "'\"$query_string\" $server_port $remote_user $remote_addr $http_x_forwarded_for '\n" +
                    "'$server_protocol \"$http_user_agent\" \"$cookie_COOKIE\" \"$http_referer\" '\n" +
                    "'$host $status $body_bytes_sent $request_time $upstream_response_time '\n" +
                    "'$upstream_addr $upstream_status';\n"
    );


    public static String generate(Slb slb) {
        StringBuilder b = new StringBuilder(1024);

//        Integer worker = slb.getNginxWorkerProcesses();

//        b.append("worker_processes ").append((worker==null||worker==0)?DEFAULT_WORKERS:worker).append(";\n");
        b.append("worker_processes auto;\n")
         .append("user nobody;\n")
         .append("error_log /opt/logs/nginx/error.log;\n")
         .append("worker_rlimit_nofile 65535;\n")
         .append("pid logs/nginx.pid;\n");


        b.append("events {\n")
         .append("worker_connections 30720;\n")
         .append("use epoll; \n")
         .append("}\n");

        b.append("http {\n");
        b.append("include    mime.types;\n");
        b.append("default_type    application/octet-stream;\n");
        b.append("keepalive_timeout    65;\n");

        b.append(logFormat.get());
        b.append("access_log /opt/logs/nginx/access.log main;\n");

        b.append(statusConf());
        b.append("include    upstreams/*.conf;\n");
        b.append("include    vhosts/*.conf;\n");
        b.append("}\n");

        return StringFormat.format(b.toString());
    }

    //slb check health
    private static String statusConf()
    {
        StringBuilder b = new StringBuilder(128);
        b.append("server {").append("\n");
        b.append("listen    ").append(String.valueOf(nginxStatusPort.get())).append(";\n");


        b.append("location / {").append("\n");
        b.append("add_header Access-Control-Allow-Origin *").append(";\n");
        b.append("check_status").append(";\n");
        b.append("}").append("\n");


        b.append("location =/status.json {").append("\n");
        b.append("add_header Access-Control-Allow-Origin *").append(";\n");
        b.append("check_status json").append(";\n");
        b.append("}").append("\n");
{'fraction_non_alphanumeric': 0.17430567387970694, 'fraction_numerical': 0.010563980235133753, 'mean_word_length': 2.897742363877822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2891197', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1785, 'n_words': 279}