我正在使用symfony为现有网站开发我的API。 但我无法像
那样配置我的symfony应用程序MyApplication#onCreate()
这里是我的nginx vhost configure
/usr/local/nginx/conf/sfapi.conf用于symfony app configure。
SharedPreferences
主要vhost conf
www.domain.com/sfapi/xxx
www.domain.com/sfapi/xxxxx
destoon.conf
location @rewriteapp {
if (-f $request_filename) {
break;
}
rewrite ^/(.*)$ /sfapi/app.php/$1 last;
}
location ^~ /sfapi/ {
alias /home/wwwroot/www.domain.com/wuye/chengshi/web;
#root /home/wwwroot/www.domain.com/wuye/chengshi/web;
index app.php;
set $root "/home/wwwroot/www.domain.com/wuye/chengshi/web";
# try to serve file directly, fallback to app.php
try_files $uri @rewriteapp;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
fastcgi.conf
server {
listen 80;
listen [::]:80;
server_name chengshi.91zhangyu.com;
rewrite ^(.*) https://$server_name$1 permanent;
}
server{
listen 443;
#listen 80;
listen [::]:443;
server_name www.domain.com;
index index.html index.htm app.php index.php default.html default.htm default.php;
ssl on;
ssl_certificate /home/certificate/www.domain.com.crt;
ssl_certificate_key /home/certificate/www.domain.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
root /home/wwwroot/www.domain.com/chengshi/chengshi;
include chengshi.wuye.conf;
include destoon.conf;
#error_page 404 /404.html;
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
#try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
include pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/www.domain.com access;
}
pathinfo.conf
rewrite ^/(.*)\.(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)$ /404.php last;
rewrite ^/(.*)/file/(.*)\.php(.*)$ /404.php last;
rewrite ^/(.*)-htm-(.*)$ /$1.php?$2 last;
rewrite ^/(.*)/show-([0-9]+)([\-])?([0-9]+)?\.html$ /$1/show.php?itemid=$2&page=$4 last;
rewrite ^/(.*)/list-([0-9]+)([\-])?([0-9]+)?\.html$ /$1/list.php?catid=$2&page=$4 last;
rewrite ^/(.*)/show/([0-9]+)/([0-9]+)?([/])?$ /$1/show.php?itemid=$2&page=$3 last;
rewrite ^/(.*)/list/([0-9]+)/([0-9]+)?([/])?(.*)?$ /$1/list.php?catid=$2&page=$3&attr=$5 last;
rewrite ^/(.*)/([A-za-z0-9_\-]+)-c([0-9]+)-([0-9]+)\.html$ /$1/list.php?catid=$3&page=$4 last;
rewrite ^(.*)/([a-z]+)/(.*)\.shtml$ $1/$2/index.php?rewrite=$3 last;
rewrite ^/(com)/([a-z0-9_\-]+)/([a-z]+)/(.*)\.html$ /index.php?homepage=$2&file=$3&rewrite=$4 last;
rewrite ^/(com)/([a-z0-9_\-]+)/([a-z]+)([/])?$ /index.php?homepage=$2&file=$3 last;
rewrite ^/(com)/([a-z0-9_\-]+)([/])?$ /index.php?homepage=$2 last;
nginx_error.log
2017/10/17 01:08:34 [错误] 20371#0:* 543重写或内部重定向循环,同时重定向到命名位置“@rewriteapp”,
感谢
答案 0 :(得分:0)
您的重写导致循环回/sfapi/
位置块。
尝试删除@rewriteapp
块,如下所示:
location ^~ /sfapi/ {
alias /home/wwwroot/www.domain.com/wuye/chengshi/web;
#root /home/wwwroot/www.domain.com/wuye/chengshi/web;
index app.php;
set $root "/home/wwwroot/www.domain.com/wuye/chengshi/web";
# try to serve file directly, fallback to app.php
try_files $uri /sfapi/app.php/$1 last;
}