一、配置Yum源

[root@test1 ~]# sudo yum install yum-utils
[root@test1 ~]# vi /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/releasever/basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/releasever/basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

//如果想使用主线版本可以运行sudo yum-config-manager --enable nginx-mainline
[root@test1 ~]# sudo yum install nginx      //这里默认采用nginx-stable稳定版本

二、配置优化

以下配置文件仅供参考

[root@test1 ~]# cat /etc/nginx/nginx.conf |egrep -v "#|^"
user nginx;
worker_processes  2;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
worker_rlimit_nofile 655350;
events {
    use epoll;
    worker_connections 2048;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  'remote_addr - remote_user [time_local] "request"http_host '
                        'statusrequest_length body_bytes_sent "http_referer" '
                        '"http_user_agent"request_time upstream_response_time';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 300m;
    tcp_nopush      on;
    server_tokens   off;
    client_body_buffer_size 512k;
    proxy_connect_timeout 60;
    proxy_read_timeout    600;
    proxy_send_timeout    600;
    proxy_buffering off;
    proxy_buffer_size     16k;
    proxy_buffers         4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary   on;
    limit_conn_zonebinary_remote_addr zone=perip:50m;
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80  default_server;
        server_name  _;
        access_log   off;
        return       444;
    }
}
[root@test1 nginx]# cat proxy_java.conf 
proxy_set_header Host host;
proxy_set_header X-Real-IPremote_addr;
proxy_set_header REMOTE-HOST remote_addr;
proxy_set_header X-Forwarded-Forproxy_add_x_forwarded_for;
[root@test1 conf.d]# cat nexus.conf 
upstream nexus {
         server 172.18.0.126:8188;
    }

server {
    listen       80;
    server_name  nexus.ssghgd.com;

    location / {
        proxy_redirect off;
        proxy_pass http://nexus;
        include proxy_java.conf;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

最后修改日期: 2019年10月15日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。