Linux上Nginx如何添加多个虚拟主机配置
2014-02-19 13:55
495 查看
配置虚拟机端口
1 添加iptables端口 vi /etc/sysconfig/iptables 找到 -A INPUT -s 172.16.0.0/16 这一行,加入新加的端口
2 重启iptables /etc/init.d/iptables restart
3 添加rewrite配置文件 在/usr/local/etc/openresty/sites-available 下创建文件
如 http-appadmin.conf
内容如下
server
{
listen 8089;
index index.html index.php;
root /var/www/cloudplatform/appstore/public/app/;
location / {
index index.html index.php;
}
location ~ \.php$ {
#auth_request /auth;
fastcgi_pass php-fcgi;
include fastcgi.conf;
}
}
4建立软连接到sites-enable里去
ln -s /usr/local/etc/openresty/sites-available/http-appadmin.conf /usr/local/etc/openresty/sites-enable/http-appadmin.conf
5重启nginx
rewrite规则:
server {
listen 8088;
charset utf-8;
gzip on;
gzip_types text/plain application/json;
gzip_proxied no_etag;
error_log /var/log/openresty/api.appstore.smartisan.cn_error.log;
access_log /var/log/openresty/api.appstore.smartisan.cn_access.log;
root /var/www/cloudplatform/appstore/public/api;
location / {
rewrite /category/list.json /appstore.php?c=category last;
if ($request_method = DELETE) {
rewrite /collect/([1-9][0-9]*).json /appstore.php?c=delCollect&aid=$1 last; #删除心愿单
return 403;
}
return 404;
}
#排行榜
location /top {
rewrite /top/size/([1-9][0-9]*)/page/([1-9][0-9]*)/list.json /appstore.php?c=top&size=$1&page=$2 last;
rewrite /top/size/([1-9][0-9]*)/list.json /appstore.php?c=top&size=$1 last;
}
#通过专题ID获取推荐列表
location ~*/([1-9][0-9]*)/topic{
rewrite /([1-9][0-9]*)/topic/size/([1-9][0-9]*)/page/([1-9][0-9]*)/list.json /appstore.php?c=getAppByTopic&tid=$1&size=$2&page=$3 last;
rewrite /([1-9][0-9]*)/topic/size/([1-9][0-9]*)/list.json /appstore.php?c=getAppByTopic&tid=$1&size=$2 last;
}
location ~*\.ico$ {
return 404;
}
location = /auth {
internal;
return 401;
}
location ~ \.php$ {
#auth_request /auth;
fastcgi_pass php-fcgi;
include fastcgi.conf;
}
location ~ /\.ht {
deny all;
}
}
1 添加iptables端口 vi /etc/sysconfig/iptables 找到 -A INPUT -s 172.16.0.0/16 这一行,加入新加的端口
2 重启iptables /etc/init.d/iptables restart
3 添加rewrite配置文件 在/usr/local/etc/openresty/sites-available 下创建文件
如 http-appadmin.conf
内容如下
server
{
listen 8089;
index index.html index.php;
root /var/www/cloudplatform/appstore/public/app/;
location / {
index index.html index.php;
}
location ~ \.php$ {
#auth_request /auth;
fastcgi_pass php-fcgi;
include fastcgi.conf;
}
}
4建立软连接到sites-enable里去
ln -s /usr/local/etc/openresty/sites-available/http-appadmin.conf /usr/local/etc/openresty/sites-enable/http-appadmin.conf
5重启nginx
rewrite规则:
server {
listen 8088;
charset utf-8;
gzip on;
gzip_types text/plain application/json;
gzip_proxied no_etag;
error_log /var/log/openresty/api.appstore.smartisan.cn_error.log;
access_log /var/log/openresty/api.appstore.smartisan.cn_access.log;
root /var/www/cloudplatform/appstore/public/api;
location / {
rewrite /category/list.json /appstore.php?c=category last;
if ($request_method = DELETE) {
rewrite /collect/([1-9][0-9]*).json /appstore.php?c=delCollect&aid=$1 last; #删除心愿单
return 403;
}
return 404;
}
#排行榜
location /top {
rewrite /top/size/([1-9][0-9]*)/page/([1-9][0-9]*)/list.json /appstore.php?c=top&size=$1&page=$2 last;
rewrite /top/size/([1-9][0-9]*)/list.json /appstore.php?c=top&size=$1 last;
}
#通过专题ID获取推荐列表
location ~*/([1-9][0-9]*)/topic{
rewrite /([1-9][0-9]*)/topic/size/([1-9][0-9]*)/page/([1-9][0-9]*)/list.json /appstore.php?c=getAppByTopic&tid=$1&size=$2&page=$3 last;
rewrite /([1-9][0-9]*)/topic/size/([1-9][0-9]*)/list.json /appstore.php?c=getAppByTopic&tid=$1&size=$2 last;
}
location ~*\.ico$ {
return 404;
}
location = /auth {
internal;
return 401;
}
location ~ \.php$ {
#auth_request /auth;
fastcgi_pass php-fcgi;
include fastcgi.conf;
}
location ~ /\.ht {
deny all;
}
}
相关文章推荐
- linux上nginx如何添加多个虚拟主机配置
- Linux上Nginx如何添加多个虚拟主机配置
- nginx如何添加多个虚拟主机配置
- Linux-NGINX 能否添加P3P头,如何添加。 - 德问:编程社交问答
- Linux下ipv6配置系列二:如何为Nginx添加ipv6模块
- Linux下如何确定Nginx安装的目录地址?
- linux下,如何把应用程序添加到Applications菜单
- 老男孩教育每日一题-第105天-Linux如何设置每天凌晨三点重启nginx服务
- Linux中如何添加/删除FTP用户并设置权限(后续)
- Linux在添加防火墙规则中如何让某一段的ip地址可以和服务器的数据互访?
- 手把手教你nginx下如何添加伪静态
- Linux系统中如何添加自己的库文件路径
- Linux 添加Nginx 到 service 启动 (完整篇)
- 如何修改Linux系统下的PATH(如何添加自己的路径到PATH)
- 如何创建和使用动态链接库与Linux下QT添加链接库使用Opencv的方法
- 安装成功的nginx如何添加未编译安装模块
- linux2.6内核中如何添加新的文件系统
- linux下如何添加一个用户并且让用户获得root权限
- Linux如何添加可用空间到一个分区
- 如何利用webmin在Linux主机中添加网站