我需要通过一些JS ajax调用在Rails应用程序中运行一些用
PHP编写的脚本.我有一个跨域问题,我的脚本在localhost / scripts上处于活动状态,我的应用程序在localhost:3000 / myapplication上处于活动状态.对localhost的Ajax请求返回跨域错误.
我能够实现jsonp解决方法,它工作正常,但我理想的是想从rails文件夹中访问PHP文件.我读到可以配置apache服务器以在框架内的文件夹上启用PHP.我在Linux上运行Apache2.
Attempted solution
我不是100%确定在哪里找到.htaccess文件,所以我只在目录中创建了一个(public / PHP-scripts).不确定这是否有效……
尝试2:
我似乎无法正确配置我的服务器:
我安装了所有乘客组件并修改了我的文件:/ etc / apache2 / sites-available / default
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.1.3/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.1.3 PassengerRuby /usr/bin/ruby1.8 <VirtualHost *:80> ServerName myservername DocumentRoot /var/www/myapp/public <Directory /var/www/myapp/public> Allow from all Options -MultiViews </Directory> </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/ <Directory /var/www/> Options FollowSymLinks AllowOverride None </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug,info,notice,warn,error,crit,# alert,emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
然后我重新启动了服务器.我错过了什么?
我导航到myservername /和myservername / myapp并获得Forbidden消息
你用apache试过
passenger吗?
这应该对你有帮助.
http://www.abletech.co.nz/blog/serving-php-from-a-rails-app-with-passenger
关键是禁用特定路线的乘客.
这适合我
把这一行放进去
/ etc / apache2 / sites-available / default或/etc/apache2/httpd.conf文件(我不是服务器配置的专家,所以决定一个,我在httpd.conf中有这个)
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.1.3/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.1.3 PassengerRuby /usr/bin/ruby1.8 <VirtualHost *:80> ServerName myservername DocumentRoot /var/www/myapp/public <Directory /var/www/myapp/public> Allow from all Options -MultiViews </Directory> # route for PHP app im my example /blog Alias /blog /var/www/blog <Location /blog> PassengerEnabled off </Location> </VirtualHost>