Ubuntu下tomcat运行PHP

Ubuntu下tomcat运行PHP

target:使用nginx作为运行PHP的服务器,同时代理tomcat,运行JSP
Date:16-04-13


安装

nginx:
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
sudo service nginx start
php:
sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql
tomcat:
wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-7/v7.0.64/bin/apache-tomcat-7.0.64.tar.gz
sudo tar zxvf apache-tomcat-7.0.64.tar.gz


配置

注意:修改时每一句都要用;分割,不然修改nginx配置会失败,nginx是启动不了的,一直都是pre-start(弄了半天才懂==)。
start fault
又或者访问不到文件
badgate

首先保存原来的(important
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old

让PHP飞起来

sudo vim /etc/nginx/sites-available/default

#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

下改成如下(主要将#删掉就行)

   location ~ \.php$ {
            include fastcgi.conf;
            fastcgi_index index.php;
    #       # With php5-cgi alone:
    #       fastcgi_pass 127.0.0.1:9000;
    #       # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

同时将index
index
改为

   # Add index.php to the list if you are using PHP
    index index.html index.htm index.php;

现在还没改root,所以在/var/www下新建test.php
test.php

启动nginx
sudo service nginx start
成功的话,应该是这样
成功后测试php

JSP跟着飞

/etc/nginx/sites-available/defaultlocation ~ .php$ {…}后添加

   location ~ \.jsp$ {
            index index.jsp;
            proxy_next_upstream http_502 http_504 error timeout invalid_header;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.01:8080;
    }

之后可以选择修改root,因为我以JSP为主,所以将

root /var/www/html;

改成(apache-tomcat-7.0.64下载在我的/home/wang/SoftWave/,webapps主要和tomcat默认配置对应)

root /home/wang/SoftWave/apache-tomcat-7.0.64/webapps;

修改后重启nginx
sudo service nginx restart
然后测试一下JSP
cd /home/wang/SoftWave/apache-tomcat-7.0.64/webapps;
mkdir test;
vim test/test.jsp
![test.jsp](https://img-blog.csdn.net/20160413212044298)
启动tomcat
cd bin/
./startup.sh`
成功后测试jsp

发布了49 篇原创文章 · 获赞 16 · 访问量 7万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章