openstack共享80、443端口的实例代码
前言
因为openstack使用的是apache,所以不能共享80端口,但创建的许多云主机,虽然可以通过rinetd进行跳转,但有时需要直接访问80端口,所以这里我们选择包含了nginx的openrety。
1.1.安装openresty
1.向centos系统中添加openresty仓库
#yuminstallyum-utils #yum-config-manager--add-repohttps://openresty.org/package/centos/openresty.repo
2.安装软件包
#yuminstallopenresty
3.安装命令行工具
#yuminstallopenresty-resty
1.2.配置openresty
1.进入nginx目录
#cd/usr/local/openresty/nginx/conf/
2.编辑nginx配置文件
#vinginx.conf userroot; worker_processes12; error_loglogs/error.log; #error_loglogs/error.lognotice; #error_loglogs/error.loginfo; #pidlogs/nginx.pid; events{ worker_connections10240; } http{ includemime.types; default_typeapplication/octet-stream; log_formatmain'$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent""$http_x_forwarded_for"'; access_loglogs/access.logmain; sendfileon; #tcp_nopushon; #keepalive_timeout0; keepalive_timeout65; #gzipon; includeconf.d/*; server{ listen80; # server_name域名; #指定日志路径 access_loglogs/access.logmain; error_loglogs/error.log; # location/{ proxy_passhttp://172.17.17.113; } } }
3.在当前目录下创建conf.d文件夹
#mkdir/usr/local/openresty/nginx/conf/conf.d #cdconf.d
4.创建要被读取的文件,目前定义为每台机器创建一台,这里定义添加一台aa机器,则创建aa.conf。
#viaa.conf server{ listen80; #绑定httpsinclude/usr/local/openresty/nginx/https/https.conf; #绑定域名 server_name域名; #指定日志路径 access_loglogs/ope.access.logmain; error_loglogs/ope.error.log; #指定通过域名跳转端口 location/{ proxy_passhttp://172.17.17.136:8081; } }
1.3. 使用openresty
1.检测nginx是否配置正确
#openresty-t nginx:theconfigurationfile/usr/local/openresty/nginx/conf/nginx.confsyntaxisok nginx:configurationfile/usr/local/openresty/nginx/conf/nginx.conftestissuccessful
2.重载openresty
#openresty-sreload
3.验证
在浏览器上输入绑定的域名即可直接访问80或者所需端口。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。