Nginx反向代理配置配置實例

爲了節省支出,公司須要將分佈在不一樣機器的站點都遷移到一臺機器,而目前不一樣機器運行的是不一樣的web服務,部分是nginx,部分是apache,因爲牽涉較多rewrite規則,爲了節省修改功夫,打算遷移後相應站點依然使用原來的web服務,可是同一臺機器80端口只能分配給一種web服務使用,因而計劃nginx使用80,apache使用其它端口例如8088,經過nginx反向代理,使apache的站點從80端口跳轉到8088端口。php

一、nginx和apache的安裝過程略過html

二、nginx的api.127.com站點反向配置
# cat api.127.com.confnginx

upstream api.127.com {
  server 127.0.0.1:8088;
  }
server{
  listen 80;
  server_name api.127.com;
  location / {
    root /home/web/api.127.com/nginx_proxy;
    proxy_redirect off ;
    proxy_set_header Host $host;
    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;
    client_max_body_size 50m;
    client_body_buffer_size 256k;
    proxy_connect_timeout 30;
    proxy_send_timeout 30;
    proxy_read_timeout 60;
    proxy_buffer_size 256k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
    proxy_max_temp_file_size 128m;
    proxy_pass http://api.127.com;
  }
}web

三、apache的api.127.com:8088站點配置
<VirtualHost *:8088>
ServerName api.127.com
ServerAlias api.127.com
DocumentRoot /home/web/api.127.com
DirectoryIndex index.html index.htm index.php
ErrorLog logs/api.127.com_error_log
CustomLog logs/api.127.com_access_log combinedapache

<Directory /home/web/api.127.com>
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>api

<Directory ~ "^/home/web/api.127.com/(.+/)*\.svn">
Order allow,deny
Deny from all
</Directory>瀏覽器

四、最終實現的效果是瀏覽器打開地址api.127.com的時候實際是訪問到api.127.com:8088ide

相關文章
相關標籤/搜索