关于nginx中 php java环境的共存服务器配置
当你的服务器linux环境 安装好了 php 和 java常见的tomcat 后 当访问java的时候端口默认为8080 那么如何让php 环境与java共存?
nginx的配置:
关键:
-
server {
listen 80;
server_name *.服务器根地址;
access_log /data/wwwlogs/access_nginx.log combined;
root /data/wwwroot/default;
index index.html index.htm index.php;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}#java 端口配置等 针对后缀
location ~ (\.jsp)|(\.do)$ { #.jsp.do是后缀
proxy_pass http://服务器ip:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#java 端口配置等 针对项目名字
location /java的项目名等 譬如 manager 【还可以写tomcat的管理页面等】)/ { #manager为项目文件夹名字
proxy_pass http://服务器ip:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}#常见的php 譬如 像 thinkphp框架的
location /yyhat/ {
if (!-e $request_filename){
rewrite ^/yyhat/(.*)$ /yyhat/index.php?s=$1 last;
}
}
#php端口配置等
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}#服务器默认的缓存配置
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
########################## vhost #############################
include vhost/*.conf;
} -
-
#常见的php 譬如 像 plahcon框架的
location /phpproject/ {
#这句话的意思是nginx的重写URL规则 可以看到把 /phpproject/后面的内容 放到了public/index.php?_url=/ 后面
rewrite ^/phpproject/(.*)$ /phpproject/public/index.php?_url=/$1;
}
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}