centOS安装nexus私服,并使用nginx代理支持Https

nexus的安装很简单,就是下载解压运行三部曲,以下是命令

#下载
wget https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.9.0-01-unix.tar.gz
#解压
tar -zxvf nexus-3.9.0-01-unix.tar.gz -C /usr/local/nexus/
//进入目录
cd /usr/local/nexus/nexus-3.9.0-01/bin/
//启动
./nexus start

这里会提示不能用root用户启动,可以自己创建用户,并赋权进行启动。

接下来说下nginx的配置

upstream  maven{
    server  172.17.4.179:8081 weight=1;
}

server {
    listen 443;
    server_name maven.zhubanxian.com;
    ssl on;
    ssl_certificate /etc/nginx/vhosts/maven/maven.pem;
    ssl_certificate_key /etc/nginx/vhosts/maven/maven.key;


    location ~ ^/(.*){
        proxy_pass http://maven;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto https;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

}

server {
    listen 80;
    server_name maven.zhubanxian.com;

    location ^~ /.well-known/acme-challenge/ {
        alias /data/sites/challenges/;
        try_files $uri = 404;
    }

    location / {
        rewrite ^/(.*)$ https://$host/$1 permanent;
    }
}

这里得注意一个小地方:proxy_set_header X-Forwarded-Proto https; 这一行配置必须加上,不然转发到nexus上的时候nexus会默认当http使用,所以这里得告诉nexus转发过去的是https的协议。

重启nginx就可以访问私服了。


版权声明:本文为zhuwei_clark原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。