前言
因為 openstack 使用的是 apache,所以不能共享 80 埠,但建立的許多雲 WordPress 主機,雖然可以透過 rinetd 進行跳轉,但有時需要直接訪問 80 埠,所以這裡我們選擇包含了 nginx 的 openrety 。
1.1. 安裝 openresty
1. 向 centos 系統中新增 openresty 倉庫

#yum install yum-utils

#yum-config-manager –add-repo https://openresty.org/package/centos/openresty.repo

2. 安裝站群軟體包

#yum install openresty

3. 安裝命令列工具

#yum install openresty-resty

1.2. 配置 openresty
1. 進入 nginx 目錄

#cd /usr/local/openresty/nginx/conf/

2. 編輯 nginx 配置檔案

#vi nginx.conf
user root;
worker_processes 12;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 10240;
}

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”‘;

access_log logs/access.log main;

sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;
include conf.d/*;

server {
listen 80;
#
server_name 域名;
#指定日誌路徑
access_log logs/access.log main;
error_log logs/error.log;

#
location / {
proxy_pass http://172.17.17.113;
}
}
}

3. 在當前目錄下建立 conf.d 資料夾

#mkdir /usr/local/openresty/nginx/conf/conf.d

#cd conf.d

4. 建立要被讀取的檔案,目前定義為每臺機器建立一臺,這裡定義新增一臺 aa 機器,則建立 aa.conf 。

#vi aa.conf
server {
listen 80;
#繫結 https include /usr/local/openresty/nginx/https/https.conf;
#繫結域名
server_name 域名;
#指定日誌路徑
access_log logs/ope.access.log main;
error_log logs/ope.error.log;

#指定透過域名跳轉埠
location / {

proxy_pass http://172.17.17.136:8081;

}
}

1.3.  使用 openresty
1. 檢測 nginx 是否配置正確

#openresty -t

nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful

2. 過載 openresty

#openresty -s reload

3. 驗證
在瀏覽器上輸入繫結的域名即可直接訪問 80 或者所需埠。