- 积分
- 21
- 威望
-
- 金钱
-
- 注册时间
- 2013-9-13
- 在线时间
- 小时
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2015-6-20 21:51:32
|
显示全部楼层
刚才看别人的帖子实验了下。
如下:
目前我有三个站点,
site1.xxx.com 要求: 只有80端口可以访问
site2.xxx.com:8089 要求 :只有8089端口可以访问
site3.xxx.com:8088 要求:只有8089端口可以访问
httpd.conf
加入 Listen 127.0.0.1:8888
vhost/site1.xxx.com .conf
<VirtualHost *:88>
ServerAdmin webmaster@example.com
php_admin_value open_basedir "/home/wwwroot/site1:/tmp/:/var/tmp/:/proc/"
DocumentRoot "/home/wwwroot/site1"
ServerNamesite1.xxx.com
ErrorLog "/home/wwwlogs/site1.xxx.com -error_log"
CustomLog "/home/wwwlogs/site1.xxx.com -access_log" common
<Directory "/home/wwwroot/site1">
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.html index.php
</Directory>
</VirtualHost>
vhost/site2.xxx.com.conf
<VirtualHost *:8888>
ServerAdmin webmaster@example.com
php_admin_value open_basedir "/home/wwwroot/site2:/tmp/:/var/tmp/:/proc/"
DocumentRoot "/home/wwwroot/site2"
ServerName site2.xxx.com
ErrorLog "/home/wwwlogs/site2.xxx.com -error_log"
CustomLog "/home/wwwlogs/site2.xxx.com -access_log" common
<Directory "/home/wwwroot/site2">
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.html index.php
</Directory>
</VirtualHost>
vhost/site3.xxx.com.conf
<VirtualHost *:8888>
ServerAdmin webmaster@example.com
php_admin_value open_basedir "/home/wwwroot/site3:/tmp/:/var/tmp/:/proc/"
DocumentRoot "/home/wwwroot/site3"
ServerName site3.xxx.com
ErrorLog "/home/wwwlogs/site3.xxx.com -error_log"
CustomLog "/home/wwwlogs/site3.xxx.com -access_log" common
<Directory "/home/wwwroot/site3">
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.html index.php
</Directory>
</VirtualHost>
nginx配置
vhost/site1.xxx.com.conf
server
{
listen 80;
#listen [::]:80;
server_name site1.xxx.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/site1;
location /
{
try_files $uri @apache;
}
location @apache
{
internal;
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}
location ~ [^/]\.php(/|$)
{
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/site1.xxx.com.log access;
}
vhost/site2.xxx.com.conf
server
{
listen 8089;
#listen [::]:80;
server_name site2.xxx.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/site2;
location /
{
try_files $uri @apache;
}
location @apache
{
internal;
proxy_pass http://127.0.0.1:8888;
include proxy.conf;
}
location ~ [^/]\.php(/|$)
{
proxy_pass http://127.0.0.1:8888;
include proxy.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/site2.xxx.com.log access;
}
vhost/site3.xxx.com.conf
server
{
listen 8088;
#listen [::]:80;
server_name site3.xxx.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/site3;
location /
{
try_files $uri @apache;
}
location @apache
{
internal;
proxy_pass http://127.0.0.1:8888;
include proxy.conf;
}
location ~ [^/]\.php(/|$)
{
proxy_pass http://127.0.0.1:8888;
include proxy.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/site3.xxx.com.log access;
}
重启apache 重启nginx
测试结果:
site1.xxx.com 正常
site1.xxx.com:8088 site1.xxx.com:8089 均显示 site3.xxx.com:8088 内容
site2.xxx.com:8089 site2.xxx.com:8088 均显示 site3.xxx.com:8088 内容
site3.xxx.com:8088 site3.xxx.com:8089 均显示 site3.xxx.com:8088 内容
我只想除了指定端口可以访问之外,输入其他端口均显示无法连接
site1.xxx.com 要求: 只有80端口可以访问
site2.xxx.com:8089 要求 :只有8089端口可以访问
site3.xxx.com:8088 要求:只有8089端口可以访问 |
|