美文网首页
nginx-单IP多端口配置

nginx-单IP多端口配置

作者: HBLong | 来源:发表于2016-09-06 14:08 被阅读2755次

    在一个服务器上部署多个站点,所以需要开放多个端口来访问不同的站点,于是在这里记录一下过程

    1.开放所需端口
    2.修改nginx配置文件
    3.重启nginx

    实例:

    假设我要开放一下站点
    119.33.33.33:1230
    119.33.33.33:80

    首先,开放所需1230端口
    iptables -A INPUT -ptcp --dport 9900 -j ACCEPT
    
    然后,修改nginx配置文件
    #path: /usr/local/nginx/conf/nginx.conf
    
    server {
    listen 80;
    server_name 119.33.33.33;
    access_log /data/www/log/119.33.33.33_nginx.log combined;
    index index.html index.htm index.php;
    include /usr/local/nginx/conf/rewrite/none.conf;
    root /data/www/website/119.33.33.33:80;
    
    
    location ~ [^/]\.php(/|$) {
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
        expires 30d;
        access_log off;
        }
    location ~ .*\.(js|css)?$ {
        expires 7d;
        access_log off;
        }
    }
    server {
    listen 1230;
    server_name 119.33.33.33:1230;
    access_log /data/www/log/119.33.33.33:1230_nginx.log combined;
    index index.html index.htm index.php;
    include /usr/local/nginx/conf/rewrite/none.conf;
    root /data/www/website/119.33.33.33:1230;
    
    
    location ~ [^/]\.php(/|$) {
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
        expires 30d;
        access_log off;
        }
    location ~ .*\.(js|css)?$ {
        expires 7d;
        access_log off;
        }
    }
    
    
    最后,命令行重启nginx
    /usr/local/nginx/sbin/nginx -s reload
    

    相关文章

      网友评论

          本文标题:nginx-单IP多端口配置

          本文链接:https://www.haomeiwen.com/subject/jrudettx.html