我这边环境是原先有个nginx只是做了代理转发,现在需要在通过nginx做yum源方便后期安装源
1、原先的配置代理转发,为不影响原先配置及端口,在http中最末尾加“include include /local/nginx/conf.d/*.conf;” 加载其它配置文件。
nginx所在服务器地址是10.7.12.10
#cat /local/nginx/conf/nginx.conf
user nginx nginx;
worker_processes 1;
pid /local/nginx/run/nginx/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘
‘$upstream_addr $upstream_response_time $request_time ‘;
log_format log404 ‘$status [$time_local] $remote_addr $host$request_uri $sent_http_location‘;
access_log logs/nginx/access.log main;
access_log logs/nginx/host.access.404.log log404;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
large_client_header_buffers 4 128k;
client_max_body_size 300m;
client_body_buffer_size 128k;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
location /status{
stub_status on;
access_log on;
auth_basic "status";
auth_basic_user_file htpasswd;
}
location /nk {
index index.html index.htm index.jsp;
proxy_pass http://10.7.12.15:8081/nk;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:$server_port;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
include /local/nginx/conf.d/*.conf; #加载其它配置文件
}
2、在 /local/nginx/conf.d/目录下建个yumrepo.conf配置文件,定义server
#vi /local/nginx/conf.d/yumrepo.conf
server {
listen 8022;
server_name localhost;
large_client_header_buffers 4 128k;
client_max_body_size 300m;
client_body_buffer_size 128k;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /yumrepo/Yumdate/rhel6;
index index.html index.htm;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
将镜像文件里面所有包拷贝到/yumrepo/Yumdate/rhel6目录下
重新reload一下nginx即可,页面可以访问看看http://IP:端口号:
3、编辑自己的repo文件
#vi /etc/yum.repos.d/yum.repo
[yumku]
name=yumku Red Hat 6.2x64 repo
baseurl=http://10.7.12.10:8022 #yum源所在服务器IP及端口,如果端口为80直接写IP即可
enable=1
gpgcheck=0
yum list 查看yum是否可用
yum clean all 清除缓存
至此nginx做yum源已搭建完成!!!
原文地址:http://blog.51cto.com/meiling/2069005
时间: 2024-11-10 14:27:52