Install nexus3 and build a private maven warehouse
Install nexus3 in docker, you will install docker by default.
Installation (recommended to use this one)
#创建docker卷
docker volume create --name nexus-data
#安装
docker run --restart=always -d -p 8081:8081 --name nexus -v nexus-data:/nexus-data sonatype/nexus3
or install like this
# 或者 指定CONTEXT(没必要,后面nginx可以转)
docker run -d -p 8081:8081 --name nexus -e NEXUS_CONTEXT=nexus sonatype/nexus3
# 或者 映射物理机目录
mkdir /some/dir/nexus-data && chown -R 200 /some/dir/nexus-data
docker run --restart=always -d -p 8081:8081 --name nexus -v /some/dir/nexus-data:/nexus-data sonatype/nexus3
# 或者 指定内存,兼容内存小的电脑,可以限制到1024
docker volume create --name nexus-data
docker run --restart=always -d -p 8081:8081 --name nexus -e NEXUS_CONTEXT=nexus -e INSTALL4J_ADD_VM_PARAMS="-Xms1024m -Xmx1024m -XX:MaxDirectMemorySize=1024m -Djava.util.prefs.userRoot=/some-other-dir" -v /some/dir/nexus-data:/nexus-data sonatype/nexus3
use of nexus3
Open the browser: http://address:8081/
First login:
Account: admin
Password: Enter the container ( docker exec -it nexus bash
) and enter the command ( cat /nexus-data/admin.password
) to view
Click Settings to create a user:
Create warehouse
Log out of the admin account, switch to the user you just created
, and click Create Warehouse
Submit the code to the repository
Set the maven-public warehouse to contain its own warehouse
In maven or gradle, set your own warehouse address
expand
Nginx adds https certificate reverse proxy nexus
After the ip is bound to the domain name, apply for the https certificate and put the certificate under nginx. The configuration of nginx is as follows
upstream nexus-server{
server 127.0.0.1:8081;
}
server {
listen 80;
server_name xx.xx;
location / {
return 301 https://xx.xx;
}
location ~ /.well-known {
root /tmp;
}
}
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/server.crt;
ssl_certificate_key /etc/nginx/server.key;
ssl_session_timeout 5m;
client_max_body_size 50m; #文件大小限制,默认1m
location /nexus {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto "https";
proxy_pass http://nexus-server/nexus;
}
location /repository {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto "https";
proxy_pass http://nexus-server/nexus/repository/maven-public/;
}
}
Note: The value of location must be equal to the context at the time of creation. For example: when creating location /nexus: NEXUS_CONTEXT=nexus