I am trying to get my app to run behind an NGINX reverse proxy and had some minor success.
the path is http://dev.sertal.ch/myApp and the application is accessible.
The issue I am still facing is that the images in the public folder are not accessible without hard coding myApp at the start of the URL. This is especially an issue for URLs inside the CSS.
You would want to set the ROOT_URL environment variable when you start your meteor app. If you are using meteor to start from the command line in your app's directory it would be like this:
ROOT_URL=http://dev.sertal.ch/myApp meteor
Meteor has a ROOT_URL property which you must explicitly set for your bundled applications.
It is in the form of Meteor.absoluteUrl([path], [options]) and the path argument is exactly what you're looking for, excerpt from the docs:
A path to append to the root URL. Do not include a leading "/".
Check here for details on options http://docs.meteor.com/#/full/meteor_absoluteurl
Related
I have build a web application using Django Rest Framework and React, I am using IIS for deployment. It works just fine but I have a problem when trying to deploy Django Admin. The style doesn't show. It shows this:
I have tried so many methods to add style to DRF project.
I used collectstatic and added it as application to IIS Manager
I activated mimetype in settings.py to accept .css
I tried to link css files in the to contrib/static with the /static url and added that into urls.py.
None of the above methods were able to solve my problem and I have stuck with this bug for days.
Could you help me to figure out this problem.
settings.py config
Your STATIC_ROOT seems to be incorrect. In fact, it will be the place where all statics will be collect by the collectstatic command.
So it has to refer to a path on your server.
You have two possibilities :
Build a relative path to a folder called "collected_static" or whatever name you want :
STATIC_ROOT = BASE_URL / 'collected_static'
Build an absolute path to a folder in your server like :
STATIC_ROOT = '/var/www/my_proj/statics
In development mode, you don't need to collect static, because django knows how to collect dynamically.
In production mode, you need to collect static, because it will provide and group all your statics inside the specified path.
After running python manage.py collectstatic, what is the response ? And can you see your expected statics in the expected folder ?
I deployed my app in example.com/app but all my routes are broken.
Oops, looks like there's no route on the client or the server for url: "http://example.com/app/."
I can try to manually prepend to all routes /app/ subfolder but it doens't seem the right approach, especially since i use a cms package (orionjs) to generate the /admin interface, which doesn't have support to change the admin path.
Is there any way to prepend the /app folder to all routes by default?
What i find strange is that i defined ROOT_URL to http://example.com/app/ but iron router seems to ignore it. Did i skip a step ?
Unlike many web platforms (ex: php), the folder structure under your app does not map automatically to routes. If you're using iron-router you basically define what layout maps to what route. The layout can be defined in an HTML file in any folder (except under /server or /public) at any depth. You can also add any extra depth you want to any route in iron-router by prepending app/ or whatever you want to your route definitions. Your ROOT_URL should remain http://example.com/
I'm implementing something like this to let one service allow access to separate upstream service in nginx.
Briefly: A Rails app sets an HMAC cookie, which is then checked by some Lua code thanks to an access_by_lua directive in nginx.
To generate and verify the cookie, both Rails and nginx-Lua must of course share a secret key. I've tried setting this up as an environment variable in /etc/environment.
To make the var available in Rails, I had to fiddle with Unicorn's init script a bit. But at least that script is contained within the project, and just symlinked into place.
Meanwhile, to get at the variable in Lua, I do something like this: os.getenv("MY_HMAC_SECRET"). But in order for Lua to have access to that when running under nginx, it must first be listed using the env directive in the main nginx config.
So now, I'm feeling like my configuration is being spread out all over the place:
in /etc/environment (outside my project)
in /etc/nginx/nginx.conf (outside my project)
in unicorn's init script
in my site's nginx vhost config
It's starting to seem a little ridiculous just to make a simple string accessible in multiple places...
Is there a simpler way to do this? Honestly, the easiest way I can think of is hardcode it in the 2 places I need it, and be done. But that sounds nasty.
Better to put it only in the two places it's actually needed, in the two respective configuration files, than in the global environment where every process has access to it, as you have it now.
I would use init_by_lua directive in your vhost config.
init_by_lua 'HMAC_SECRET = "SECRET-STRING"';
server {
# and so on
}
So you'll have you secret in two places, but both in your project (if I understand correctly and vhost config is in your project).
You can even use init_by_lua_file and make some efforts to read and parse that file in your unicorn init.
I am wondering if it is possible to choose environment when generating urls with the symfony routing component.
In a controller
$this->generateUrl($route, $params);
generates / in prod envrionment and /app_dev.php in dev.
There doesn't seem to be a parameter for the environment so that you could generate productive urls in dev environment. I just don't want to use something like str_replace all the time.
This would be great:
$this->generateUrl($route, $params, 'prod');
For your understanding, I am working on a cms project where I have to match uris against the database where they are stored without app_dev.php.
Any ideas?
More of a hack than a proper solution, you can set the Context's $baseUrl to be '' (as it would in production environment) before calling the generateUrl and reset-ting it back after the call. The RequestContext->getBaseUrl is consulted each time the complete Url is built.
In our case, we had to build Urls without the app_dev or app.php because our frontend was an AngularJS based application matching the URLs. In this case, since we dint want the app_dev or app.php at all, we created an EventListener that does a
$this->router->getContext()->setBaseUrl('');
Router component workflow doesn't include any of app.php or app_dev.php files. It only works with the pattern which comes after php file in the query string, whatever that file is.
So you're not able to do that. You only can use .htaccess file config to manage what file will be used as a default one, no more.
I have an application in Symfony 2. It is deployed on IIS server.
The problem is, I need to get it work on multiple URLs:
www.somedomain.com/myapp/app.php - for production
www.somedomain.com/myappdev/app.php - for testing
myapp.localhost/app.php - for development
How can I do that? I need to correctly generate URL for resources(js, css files). Also after deployment, generated URL are missing the /myapp/ (/myappdev/) segment.
You can prefix your routes with /myappdev by adding it to your app/config/routing.yml file under the prefix key.
If you use relative URLs for the resources then you won't have a problem with the domain it's on and it will work anywhere you put it.