ubuntu二级域名转发和同时附上php java同时存在环境
目前项目以部署了一套java web环境,但后来想在work.域名.com部署一套php 工作流系统
一.前言
在阿里云域名设置二级域名
部署号java 环境(tomcat mysql java sdk),[若不熟悉可见 jdk tomcat mysql安装]
然后www.域名.com ,访问成功
二.安装php
sudo apt-get install php5 libapache2-mod-php5
sudo /etc/init.d/apache2 restart(重启apache)
三.安装apache2
1.输入命令:sudo apt-get install apache2即可安装,
安装完后,打开浏览器,在地址栏输入:localhost或者http://127.0.0.1
看到It works,表示安装成功!
默认根目录:/var/www/
2.让apache和php支持php :
sudo apt-get install libapache2-mod-auth-mysql
sudo apt-get install php5-mysql
sudo /etc/init.d/apache2 restart(重启apache)
3.然后在 /var/www/ 下新建test.php,如下内容上传后,访问,会提示成功
<?php
echo "php 程序.....start mysql connect...";
try{
#$link=mysql_connect("120.26.130.20","root","1314159");
$link=mysql_connect("127.0.0.1","root","1314159");
if(!$link) echo "FAILD!连接错误,用户名密码不对";
else echo "OK!可以连接";
}catch(PDOException $e){
echo "error".$e->getMessage()."</br>";
die();
}
?>
4.将apache2 端口设置8081
在ports.conf 设置Listen 8081,并sites-available/000-defaut.conf设置<VirtualHost *:8081>
并将 tomcat 设置8080;
四.安装nginx
1. apt-get install nginx
2.访问 会 提示nginx 成功
3./etc/nginx/sites-available/default替换server 节点
server {
listen 80;
server_name 域名.com;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}server {
listen 80;
server_name www.域名.com;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name work.域名.com;
location / {
proxy_pass http://localhost:8081/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name www.work.域名.com;
location / {
proxy_pass http://localhost:8081/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
参考资料
1.service nginx status
etc/init.d/mysqld start
sudo /etc/init.d/apache2 restart
2.手把手教你在ubuntu上安装apache和mysql和php