近日有一需求,需要在一台主机上用nginx部署2个php应用,分别是wordpress和wiki,探索了半天,终于部署好了,下面把过程记录下来。
1. 在nginx下创建vhosts目录,用以放置vhost文件。
mkdir vhosts
2. 修改nginx.conf的配置, 在http节点增加下面内容设置,用来包含vhosts里的配置文件
# vhosts files include /usr/local/nginx/vhosts/*;
3. 在vhosts下创建testwp.com.conf和duwiki.com.conf文件, 注意:这里的配置文件以conf结尾
testwp.com.conf
server{ listen 80; server_name www.testwp.com; location / { root /Users/jiangzhiqiang/phpwork/wordpress; index index.php index.html index.htm; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /Users/jiangzhiqiang/phpwork/wordpress; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; # $document_root指前面的root路径 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
duwiki.com.conf
server { listen 80; server_name www.duwiki.com; location / { root /Users/jiangzhiqiang/phpwork/dokuwiki; index index.php index.html index.htm; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /Users/jiangzhiqiang/phpwork/dokuwiki; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to files, dokuwiki settings location ~ /(data|conf|bin|inc)/ { deny all; } }
carbon.conf
server { listen 80; server_name www.carbon.com; location / { root /Users/jiangzhiqiang/phpwork/carbon; index index.php index.html index.htm; } # nginx configuration error_page 404 /404.php; rewrite ^([^\.]*)/dashboard$ $1/dashboard.php; rewrite ^([^\.]*)/favorites(/page/([0-9]*))?$ $1/favorites.php?page=$3 last; rewrite ^([^\.]*)/json/([0-9a-z_-]+)$ $1/json.php?action=$2 last; rewrite ^([^\.]*)/login$ $1/login.php; rewrite ^([^\.]*)/manage$ $1/manage.php; rewrite ^([^\.]*)/new$ $1/new.php; rewrite ^([^\.]*)/notifications$ $1/notifications.php; rewrite ^([^\.]*)/page/([0-9]+)$ $1/index.php?page=$2 last; rewrite ^([^\.]*)/register$ $1/register.php; rewrite ^([^\.]*)/reply$ $1/reply.php; rewrite ^([^\.]*)/robots.txt$ $1/robots.php; rewrite ^([^\.]*)/search.xml$ $1/open_search.php; rewrite ^([^\.]*)/search/(.*?)(/page/([0-9]*))?$ $1/search.php?keyword=$2&page=$4 last; rewrite ^([^\.]*)/settings$ $1/settings.php; rewrite ^([^\.]*)/sitemap-(topics|pages|tags|users|index)(-([0-9]+))?.xml$ $1/sitemap.php?action=$2&page=$4 last; rewrite ^([^\.]*)/statistics$ $1/statistics.php; rewrite ^([^\.]*)/t/([0-9]+)(-([0-9]*))?$ $1/topic.php?id=$2&page=$4 last; rewrite ^([^\.]*)/tag/(.*?)(/page/([0-9]*))?$ $1/tag.php?name=$2&page=$4 last; rewrite ^([^\.]*)/tags/following(/page/([0-9]*))?$ $1/favorite_tags.php?page=$3 last; rewrite ^([^\.]*)/u/(.*?)$ $1/user.php?username=$2 last; rewrite ^([^\.]*)/users/following(/page/([0-9]*))?$ $1/favorite_users.php?page=$3 last; rewrite ^([^\.]*)/upload_controller$ $1/upload_controller.php; #QSA is automatic in nginx. rewrite ^([^\.]*)/view-(desktop|mobile)$ $1/view.php?view=$2 last; # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /Users/jiangzhiqiang/phpwork/carbon; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to files, settings location ~ /(data|conf|bin|inc)/ { deny all; } }
4. 修改hosts文件
sudo vi /etc/hosts 127.0.0.1 www.testwp.com 127.0.0.1 www.duwiki.com 127.0.0.1 www.carbon.com
5. 重启 nginx
sudo nginx -s reload
在浏览器url栏输入 www.testwp.com, 就访问到本地部署的wordpress应用,访问 www.duwiki.com,就访问到本地部署的 dokuwiki 应用。
相关推荐
主要介绍了详解nginx同一端口监听多个域名和同时监听http与https的相关资料,需要的朋友可以参考下
nginx一个域名多个项目部署,nginx一个域名多个项目部署,nginx一个域名多个项目部署,nginx一个域名多个项目部署
为了节约成本,很多时候一台server 的nginx可能要部署多个前端的情况,本实例是在docker环境下部署两个前端,同时处理前端调用后端跨域问题,本示例为阿里云centos7 系统docker20.10.6环境下nginx1.19.5版本 ...
主要介绍了nginx部署多个vue项目的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
一:nginx同一端口监听多个域名和同时监听http,https 分享者:weikle,来自原文地址 1、同一端口监听多个域名 如今公网ip资源越来越珍贵,多域名监听应用非常广泛,就是用一个端口,比如80或者443,监听多个入口...
docker部署nginx,挂载多个前端部署目录以及跨域问题解决方案(1).zip
nginx是目前开源web中,最常用到web网站服务,提供高效稳定的网站服务。此文件提供安装部署、配置说明、应用场景演示。
Nginx 安装与配置 Nginx 配置文件详解 Nginx 命令参数 ...配置Nginx的虚拟主机 配置Nginx的用户认证 配置Nginx提供状态页面 配置Nginx的错误页面 配置Nginx打开目录浏览功能 配置Nginx基于ssl提供https服务
centos7配置nginx虚拟主机
一、nginx介绍及功能讲解 二、nginx的安装 三、nginx配置相关指令 四、nginx的实例应用(项目部署)
Linux下Nginx的安装部署 1、手动下载安装包 2、解压、编译安装 3、启动、停止、重启 nginx 4、开机自启动 5、环境配置
带有nginx的Docker可以在同一服务器上维护多个Web应用程序或站点 描述 该场景如下: 一台服务器 在Docker容器中运行的几个站点/ Web应用程序 两个网络: 仅具有Nginx代理服务器的前端网络 只能通过nginx访问的...
django项目+nginx+uwsgi部署,ubuntu和centos下都实用。
主要介绍了docker nginx 部署多个项目的示例方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
nginx安装插件包和部署包含了文档和脚本以及其中nginx的安装包是直接在linux在线下载。不是非常详细啊!
利用yum(黄狗)安装nginx,mysql,通过下载tomcat,jdk并安装。此处用mysql数据库(修改明文密码为复杂密码,不区分大小写设置)。设置tomcat,nginx相应的端口,路径等等。有需要即下载吧!
背景介绍最近在个人的多个项目部署中遇到这样一个问题,一个域名如何实现多个项目的访问。因为不想自己单独去申请域名证书和域名配置,便想到了这个方案,结合Nginx的
基于海思3559A 对nginx-1.6.2 openssl-1.0.2的交叉编译过程,nginx-1.6.2的环境部署
nginx虚拟主机配置及详细讲解介绍。。。。。。。