关闭

nginx配置多个虚拟ip访问

标签: ngnixip
2668人阅读 评论(0) 收藏 举报
分类:

nginx配置文件:

#user  nobody;
worker_processes  4;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/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"';

    access_log  logs/access.log  main;

    sendfile        on;
    tcp_nopush      on;

    #keepalive_timeout  0;
    keepalive_timeout  90;

    #gzip  on;

    server {
        listen       192.168.88.134:8080;
        server_name  192.168.88.134;

        #charset koi8-r;

        access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm index.php;
			#autoindex on;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
           root           html;
           fastcgi_pass   127.0.0.1:9999;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
        }
        location ~ \.cgi$ {    //配置cgi程序
           root           html;
           fastcgi_pass   127.0.0.1:7000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
}


Ubuntu 配置多个ip地址:/etc/network/interfaces

root@ubuntu:/etc/network# cat interfaces 
auto eth0
iface eth0 inet static
address 192.168.88.134
netmask 255.255.255.0
gateway 192.168.88.1

auto eth0:1
iface eth0:1 inet static
address 192.168.88.135
netmask 255.255.255.0
up route add -host 192.168.88.135 dev eth0:1

auto eth0:2
iface eth0:2 inet static
address 192.168.88.136
netmask 255.255.255.0
up route add -host 192.168.88.136 dev eth0:2

重启nginx及spawn-fcgi程序

重启网络:/etc/init.d/networking restart

http://192.168.88.136:8080/test.cgi

http://192.168.88.135:8080/test.cgi

http://192.168.88.134:8080/test.cgi


均能正常访问了

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:213493次
    • 积分:4019
    • 等级:
    • 排名:第7763名
    • 原创:186篇
    • 转载:125篇
    • 译文:0篇
    • 评论:9条
    文章分类
    最新评论