-
安装nginx
这里就不详细说了,网上很多 -
设置用户与组
groupadd -g 2222 apache
useradd -d /home/nginx -m -g apache -u 4444 nginx
chmod -R 755 /home/nginx
chown -R nginx:apache /home/nginx
chage -M 99999 nginx
chage -d 0 nginx
usermod -s /bin/false nginx
echo '* - nofile 100000' >> /etc/security/limits.conf
- 新增nginx配置
这里将/home/nginx/YUM_nginx/yum_path作为yum源路径,访问URL为:本机IP:10235
cp -r /etc/nginx/ /home/nginx/YUM_nginx
mkdir -p /home/nginx/YUM_nginx/logs
cat << EOF > /home/nginx/YUM_nginx/nginx.conf
user nginx apache;
worker_processes 4;
error_log /home/nginx/YUM_nginx/logs/error.log warn;
pid /home/nginx/YUM_nginx/logs/nginx.pid;
events {
multi_accept on;
worker_connections 10240;
use epoll;
}
http {
include /home/nginx/YUM_nginx/mime.types;
default_type application/octet-stream;
access_log /home/nginx/YUM_nginx/logs/access.log xtsformat;
sendfile on;
tcp_nopush on;
keepalive_timeout 65s;
keepalive_requests 100;
server_tokens off;
reset_timedout_connection on;
client_header_timeout 60s;
client_header_buffer_size 4K;
client_body_timeout 60s;
client_body_buffer_size 16K;
send_timeout 60;
server {
listen 10235;
server_name localhost;
location = /50x.html {
root /home/nginx/YUM_nginx/html;
}
root /home/nginx/YUM_nginx/yum_path;
location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}
}
EOF
- 配置systemd
cat << EOF > /usr/lib/systemd/system/yum-nginx.service
[Unit]
Description=The NGINX HTTP for yum
[Service]
Type=forking
ExecStartPre=/usr/sbin/nginx -c /home/nginx/YUM_nginx/nginx.conf -t
ExecStart=/usr/sbin/nginx -c /home/nginx/YUM_nginx/nginx.conf
ExecReload=/usr/sbin/nginx -c /home/nginx/YUM_nginx/nginx.conf -s reload
ExecStop=/usr/sbin/nginx -c /home/nginx/YUM_nginx/nginx.conf -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemd enable yum-nginx.service
systemd start yum-nginx.service
- 配置客户端
cat << EOF > /etc/yum.repos.d/my.repo
[upel]
name=myrepo
baseurl=http://127.0.0.1:10235
enabled=1
gpgcheck=0
EOF