nginx-单IP多端口配置

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

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一章 Nginx简介 Nginx是什么 没有听过Nginx?那么一定听过它的“同行”Apache吧!Ngi...
    JokerW阅读 32,897评论 24 1,002
  • 对于Nginx,一个IP上配置多个站点还是很常见的。尤其是在开发环境上,更是如此。 下面在我的阿里云上简单的实现这...
    尽情的嘲笑我吧阅读 8,412评论 0 7
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,797评论 19 139
  • 名词延伸 通俗的说,域名就相当于一个家庭的门牌号码,别人通过这个号码可以很容易的找到你。如果把IP地址比作一间房子...
    杨大虾阅读 20,694评论 2 56
  • 圆圆脸蛋调皮蛋, 萌萌酒窝腮边漩。 梦里游戏醒方觉, 思女情愫千涌泉。 生活所为两相盼, 唯求莫把父母怨。 誓得团...
    为你钟情Leslie阅读 1,839评论 0 1