ubuntu二级域名转发和同时附上php java同时存在环境

前端之家收集整理的这篇文章主要介绍了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","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

原文链接:https://www.f2er.com/ubuntu/351649.html

猜你在找的Ubuntu相关文章