The Coding World

其实生命就是一个过程,到最后一天你啥也带不走,精彩的是你留下什么。

nginx配置多个虚拟ip访问

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


均能正常访问了

阅读更多
文章标签: ngnix ip
个人分类: c/c++ linux学习
上一篇nginx服务器下编写cgi程序
下一篇nginx配置反向代理服务
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭