Okay, I've been struggling on development because of this cross domain restriction on my php-angular application development.
I am using yeoman to scaffold my application thus it has a grunt task of server which opens an http server at port 9001
Now I have created a REST-like api in php as my backend to provide service to my angularjs application.
During development I always create a dummy data in instead of using that api I made because I cannot make those two separate things together, then after I am finish building the front end, I will build it and copy to the folder of the api, so I can now test it to work together, which is really not so efficient and fast for development.
Now I came across this article
That taught how to make those two work together, but I think I failed to understand and failed to do it properly.
Here is my configuration for a site-available in apache.
<VirtualHost *:80>
ServerName foo.dev
ServerALias www.foo.dev
DocumentRoot /var/www/html/foo
ProxyPass /api/ http://foo.dev/api/ retry=0 timeout=30
ProxyPass / http://localhost:9001/ retry=0 timeout=30
<Directory "/var/www/html/foo">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
What happens now, is that http://foo.dev now works, just like what I see in localhost:9001, but it cannot access http://foo.dev/api
What is wrong in my setup. Thanks!
If you backend has created with PHP, you will need create a .htaccess file in the root directory of you PHP.
Set this:
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "X-Requested-With, Content-Type"
</ifModule>
Related
I am attempting to access OrientDB's REST API through a reverse proxy. That is, I have a domain orientdb.mydomain.com that forwards to localhost:2480, where the server is. I have this working on the unsecured website, so I can access http://orientdb.mydomain.com and it brings up the studio site:
http://orientdb.mydomain.com/studio/index.html
However, this does not work through https. I get a 404 error ("The requested URL /studio/index.html was not found on this server")
I have a feeling that I'm not using the correct documentroot or there is something funny about OrientDB that it's generating the path above in another way. I cannot actually find this /studio directory anywhere.
This is from my virtualhost setting in my ssl.conf file.
<VirtualHost _default_:443>
DocumentRoot "/opt/orientdb-3.0.6/www"
<Directory "/opt/orientdb-3.0.6/www">
Require all granted
</Directory>
ServerName orientdb.mydomain.com
#more stuff
</VirtualHost>
By the way, I originally had the following options in my Directory tag, but it gave a forbidden error. I changed it to Require all granted and it now says not found- so I think I'm making progress.
AllowOverride All
Order allow,deny
In summary, is it possible to access the OrientDB server in this way and if so what do I put as DocumentRoot, etc?
I don't think you can do that.
OrientDB has its own HTTP server embedded so the only way it can work is with the reverse proxy configuration.
You can expose your web server (apache HTTP I guess) in https and terminate the "s" there, proxying to orientdb HTTP port (2480).
This turned out not to be an OrientDB issue, but a proxy issue. I had used a virtualhost to set up the proxy on port 80, but I did not do the same for port 443. After adding these settings to my 443 virtualhost on orientdb.mydomain.com, I was able to access the studio and the HTTP REST API through HTTPS.
ProxyPass / http://127.0.0.1:2480/
ProxyPassReverse / http://127.0.0.1:2480/
<Proxy *>
Require all granted
</Proxy>
As part of upgrading a legacy Java application (hosted on Weblogic cluster), one section of this application will be replaced by a single page application (REACT), calling out over an API to various services that contain migrated backend functionality. For now until all UI dependencies are ported off the legacy application, the REACT SPA will still be hosted inside a JSP page (some common JSP code has not been ported, and so will be present on the JSP page hosting the react app).
The infrastructure hosting this setup is currently an Apache server, routing to the Weblogic cluster or newer services as needed. Proxying to the weblogic cluster was simple before, as all *.jsp pages were routed to the cluster with a simple weblogic plugin block:
<IfModule mod_weblogic.c>
WebLogicCluster server1:port,server2:port
MatchExpression *.jsp
</IfModule>
However with the new SPA, I also need a whole set of routes to proxy to a single .jsp page containing my SPA. If my goal was only to proxy by path, I could solve that easily with apache weblogic plugin:
<Location /newSection/>
WLSRequest On
WebLogicCluster server1:port,server2:port
PathTrim /newSection/
PathPrepend SPA.jsp
DefaultFileName SPA.jsp
</Location>
However this only works for the base /newSection/ url, as a url like
http://host/newSection/spa-route
gets proxied to
http://host/SPA.jsp/spa-route
which is obviously not valid.
No amount of PathTrim, PathPrepend, or anything else I try for the weblogic plugin solves the problem that I am trying to proxy by path to a single URI (everything needs to proxy to http://host/SPA.jsp, SPA router handles the rest)
I am currently experimenting with just using mod_rewrite and mod_proxy instead, as RewriteRule [P] allows me to proxy to a single URI on the cluster (cluster IP coming from Proxy balancer). However this is much more complicated to set up (still trying), and I have to implement things like session stickiness myself.
A solution for how to use the mod_weblogic plugin to proxy to a particular URI would be great, but examples of how to use mod_rewrite, mod_proxy, and/or mod_proxy_balancer to achieve this proxying to a single URI on a weblogic cluster would be extremely helpful as well.
Turns out there was an apache feature (Passthrough) I was not aware of (or at least how exactly it works) that can bridge Apache rewrite rules to the weblogic plugin nicely.
RewriteRule /newSection/.*$ /SPA.jsp [PT,L]
The passthrough rewrites the URI to http://host/SPA.jsp WITHOUT doing a rewrite. The passthrough then explicitly passes that new URI back through the rule stack and other modules. At this point the original weblogic plugin rule I had that proxies by MIME type to the cluster (*.jsp) will pick up the URI and work nicely.
This way Apache takes care of rewriting a set of paths to a specific URI, and the weblogic plugin nicely takes care of the rest (proxying to cluster, load balancing, sticky sessions, etc.)
Here is how you use weblogic plugin to direct individual urls, feel free to change options as per your requirement:
Create a virtual host file:
<VirtualHost *:80>
SSLEngine on
ServerName fqdn
ServerAlias alias
ServerAdmin webmaster#localhost
Header always append X-Frame-Options DENY
DocumentRoot /var/apache2/htdocs
<Directory /var/apache2/htdocs>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule mod_weblogic.c>
debug ERR
FileCaching on
WLIOTimeoutSecs 600
Idempotent ON
FileCaching ON
DynamicServerList ON
KeepAliveEnabled OFF
<Location /newsection>
SetHandler weblogic-handler
WebLogicCluster host1:port,host2:port
</Location>
<Location /newsection/SPA.jsp>
SetHandler weblogic-handler
WebLogicCluster host3:port,host4:port
</Location>
<Location /SPA.jsp>
SetHandler weblogic-handler
WebLogicCluster host5:port,host6:port
</Location>
</IfModule>
</VirtualHost>
I am trying to develop a RESTful service using Apache 2 and mod_fastcgi as my transport and security layer.
What I am trying to achieve is that a C++-application is called when a request is made. Then I want to use the HTTP method and the URI to decide (inside the application) which of the (internal) resources should be accessed and in which way.
Calling my C++-FastCGI application works (located # /var/www/html/foo/fastcgi_test). But only with a specific URI - the URI where my binary is located:
If I open http://127.0.0.1/foo/fastcgi_test in a browser my application runs and returns a html test page like I want.
Trying e.g. http://127.0.0.1/foo/bar returns a page with a 404. But I would like the same application to be called (fastcgi_test).
My configuration (so far) looks like this:
<IfModule mod_fastcgi.c>
FastCgiIpcDir /var/lib/apache2/fastcgi
<Location /foo>
SetHandler fastcgi-script
</Location>
FastCgiServer /var/www/html/foo/fastcgi_test -flush
</IfModule>
I read the mod_fastcgi manual and dug through the Apache manuals, but I can't find the right hint. It seems I don't seach for the right key word.
As I am very new to Apache configuration I maybe/hopefully just miss the right starting point.
How do I configure Apache/mod_fastcgi to send requests to a "branch of URIs" to the same FastCGI process? Can somebody provide a pointer?
The key is to use an alias. I also moved the FastCGI program out of the content area of Apache into a separate directory (/var/www/fastcgi).
My solution looks like this:
<IfModule mod_fastcgi.c>
FastCgiIpcDir /var/lib/apache2/fastcgi
<Directory /var/www/fastcgi>
SetHandler fastcgi-script
</Directory>
<Location "/foo">
Require all granted
</Location>
FastCgiServer /var/www/fastcgi/fastcgi_test -flush
AliasMatch "/foo(.*)" "/var/www/fastcgi/fastcgi_test"
</IfModule>
I'm trying to configure mod_mono with Apache2 on OSX. I would like to run multiple MVC3 projects on the same virtual host, but for some reason only the first one listed is working. Any help on this would be much appreciated as there is not much documentation on this. I've tried a lot of different config options, none of which seem to work.
Listen *:9005
<VirtualHost *:9005>
DocumentRoot "/Library/WebServer/vhosts/api"
ServerName api
MonoAutoApplication disabled
Alias /gamecenter "/Library/WebServer/vhosts/api/gamecenter"
AddMonoApplications gamecenter "/gamecenter:/Library/WebServer/vhosts/api/gamecenter"
MonoServerPath gamecenter "/usr/bin/mod-mono-server4"
MonoDebug gamecenter true
MonoSetEnv gamecenter MONO_IOMAP=all
MonoUnixSocket gamecenter-stage /tmp/mod_mono_server_gc
<Location /gamecenter>
Allow from all
Order allow,deny
MonoSetServerAlias gamecenter
SetHandler mono
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
</Location>
Alias /gamecenter-stage "/Library/WebServer/vhosts/api/gamecenter-stage"
MonoServerPath gamecenter-stage "/usr/bin/mod-mono-server4"
MonoDebug gamecenter-stage true
MonoSetEnv gamecenter-stage MONO_IOMAP=all
AddMonoApplications gamecenter-stage "/gamecenter-stage:/Library/WebServer/vhosts/api/gamecenter-stage"
MonoUnixSocket gamecenter-stage /tmp/mod_mono_server_gcs
<Location /gamecenter-stage>
Allow from all
Order allow,deny
MonoSetServerAlias gamecenter-stage
SetHandler mono
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
</Location>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
</IfModule>
</VirtualHost>
your problem is that your Alias name and physical path are one and the same, so apache doesn't know which one to serve up.
NOTE: I'm giving the answer based on general Apache2 configuration, and not on mod_mono, maybe mod_mono does something to prevent this, I've not set MVC apps up under a *nix box before :-)
Anyway...
if you look at your path configurations you have...
/Library/WebServer/vhosts/api
/Library/WebServer/vhosts/api/gamecenter
/Library/WebServer/vhosts/api/gamecenter-stage
without your aliases in place, these already resolve to the paths your trying to map.
/Library/WebServer/vhosts/api = /
/Library/WebServer/vhosts/api/gamecenter = /gamecenter
/Library/WebServer/vhosts/api/gamecenter-stage = /gamecenter-stage
Your then telling Apache that
/ = /
/gamecenter = /gamecenter
/gamecenter-stage = /gamecenter-stage
When Apache tries to deliver the content if there is no file subfix or existing slash (as in the last 2) it will automatically, subfix the folder with a / then issue a redirect (306 I believe) essentially telling the browser to redirect from EG:
/gamecenter to /gamecenter/
With the alias in place to tell it that Alias ... is at location x it then has to try and make a desicion to serve
/gamecenter/
or
/gamecenter/gamecenter/../ (Because in terms of folder structure the alias name is 1 folder level down in the web than it is physically)
and ends up getting confused, and so does what any virtual host set up does when it's unable to resolve the path, and that's return the website root.
AS I SAY however, this is general NON-MONO Apache behaviour, it is possible that mod_mono may alter the processing pipeline in some way to that may change this behaviour.
What I would recommend is to split this into 3 virtual hosts which you can do very very easily even on just one IP.
First thing you'll want to do is somwhere in your master Apache config file, have a
Listen 9005
statement. This will make ALL virtual instances listen on that port as well as any other configured port EG: 80
Next make sure you have a default catch all virtual host, this will catch any server name not mapped elsewhere:
<VirtualHost *>
DocumentRoot "/some/folder/where/the/default/is/"
#Followed by other server directives. NOTE: there is NO servername line
</VirtualHost>
Once you have that set up, then move onto your "api" sub domain
<VirtualHost *>
ServerName api
DocumentRoot "/Library/WebServer/vhosts/api/"
#Other required directives here
</VirtualHost>
At this point, I'm going to pause to discuss your domain name. If this is an internal test system (Which I suspect it is) then you'll find life with virtual domains way easier if you install a DNS server on you box, then set that up as a master domain using a private internal network address.
EG:
Create a root zone, and call it "mydevnetwork.local"
then add machine names to it:
EG: if your pc is called devpc1, create an IP address for "devpc1.mydevnetwork.local" and give your pc a static IP address of EG: 192.168.50.1
Then set an alias for that so
api.mydevnetwork.local = devpc1.mydevnetwork.local
Iv'e not got the room to do a full DNS setup post here, but hopefully you get the idea.
Once you have DNS (or at a minimum host file entries) set up, then your virtual hosts under Apache become really easy to manage:
<VirtualHost *>
ServerName api.mydevnetwork.local
DocumentRoot "/Library/WebServer/vhosts/api/"
#Other required directives here
</VirtualHost>
and easy to relocate to another machine should you need too.
You can set the rest of your virtual hosts up in much the same way
<VirtualHost *>
ServerName gamecenter.mydevnetwork.local
DocumentRoot "/Library/WebServer/vhosts/api/gamecenter/"
#Other required directives here
</VirtualHost>
<VirtualHost *>
ServerName gamecenter-stage.mydevnetwork.local
DocumentRoot "/Library/WebServer/vhosts/api/gamecenter-stage/"
#Other required directives here
</VirtualHost>
Note iv'e set the paths to be the same as you had above, and even though this will work, I'd strongly advise that you give each one it's own unique folder, I generally do something like:
wwwroot
api.mydevnetwork.local
htdocs <-- Web files go here
cgi-bin <-- cgi scripts go here and it's mapped to /cgi-bin/
logs <-- logs here
access <-- htpasswd files here
Hopefully if the above is not a complete solution, you might at least get some further ideas of investigation from it.
I wish I had never seen this article:
http://www.magentocommerce.com/knowledge-base/entry/tutorial-multi-site-multi-domain-setup
I have Apache 2.2 installed on my XP machine and until a while ago I had a Magento site that I could test the development of a custom module on. I decided that I wanted to have multiple websites and multiple stores so that I could test that my modules configuration variables set at the different scopes (global, website, and store) were working as expected.
So I followed the instructions in the above Magento article. I created a website and gave it a name of “paulsplace.com”. I created a couple of Stores under that website. I then went to System/Configuration/General/Web and, with the scope set to paulsplace.com, I set the unsecured and secured URLs to http://paulsplace.com/ and https://paulsplace.com/ and hit Save Config - what a mistake!!
I got a 404 error. And now I can’t get to my magento front end or back end.
I tried a couple of things:
I added these lines to my hosts lookup file:
127.0.0.1 paulsplace.com
127.0.0.1 www.paulsplace.com
I then uncommented this line in my httpd,conf file:
Include conf/extra/httpd-hosts.conf
and added the following to the conf/extra/httpd-hosts.conf file:
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "C:/Applications/Apache Software Foundation/Apache2.2/htdocs"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
</VirtualHost>
and restarted Apache.
If I browse to “http://www.paulsplace.com” I now get a page that just says “It works!”. Same for “http://paulsplace.com” and “http://www.paulsplace.com/magento/index.php”.
I tried a few more things - I added this line to httpd.conf:
AccessFileName htaccess
(I did this because Windows Explorer didn’t let me create a file starting with a dot; I could do it from the command prompt, but I believe what I have done should be ok).
I changed AllowOverride to All from None:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
<Directory "C:/Applications/Apache Software Foundation/Apache2.2/htdocs">
AllowOverride All
</Directory>
and in C:\Applications\Apache Software Foundation\Apache2.2\htdocs\htaccess (a file that I created), I entered:
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host ^paulsplace\.com MAGE_RUN_TYPE=website
(pws was the value I used for the “Code” when creating my store).
Please tell me how I can put this right. I feel like I’m taking one step forward and three backward at the moment.
Any help really would be greatly appreciated.
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "Change this to point at your magento install"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
SetEnv MAGE_RUN_TYPE website
SetEnv MAGE_RUN_CODE pws1
</VirtualHost>
If changing anything in System Configuration borks your system, you can always clear out the bad values in the database directly, and clear your Magento cache. Do a
select * from core_config_data where value LIKE '%paulsplace.com%'
This will give you the two rows that were added when you clicked save. Remove the rows. Next, clear out all the files in
var/cache/*
to clear your cache. Then restore your Apache config to what it was before you started monkeying around. This should restore your site back to its previous state, and you can continue to experiment with things.