WSGI path doen't work with Amazon Linux 2 - amazon-elastic-beanstalk

I'm trying to get going with Elastic Beanstalk and Amazon Linux 2. One thing I've noticed is that the WSGI path seems to be a little different.
For a Django app I would usually set <<app_name>>.wsgi.py
Instead, the new way to define it is with a namespace like this. This, however, does not seem to work from the eb config buy only from .ebextensions
<<app_name>>.wsgi:application
I feel like, I'm doing something wrong here or not getting this namespace concept?
Why do I suddenly have to add a namespace?

Since other people may run into this issue.
Here is the fix to my problem:
Amazon Linux 2 uses Gunicorn as it's default webserver. Gunicorn expects a certain syntax when specifying the Path to the WSGI config. This syntax does not only include the path to the file but also the name of the exported function (or class) accepting the WSGI parameters.
This is why you have to use the syntax above.
There are several ways to specify the WSGI path for your project. You can do it via the AWS gui but my recommendation would be to add a Procfile to your project.
My Procfile looks like this:
web: gunicorn --bind :8000 --workers 3 --threads 2 <<my_app>>.wsgi:application

Related

Gunicorn: No module named '/path/to/my/django/project'

I was using gunicorn with nginx on Ubuntu 16.04 system to deploy a django project and want to create a systemd service for gunicorn. In /lib/systemd/system/gunicorn-mywebsite.service, I write following codes:
ExecStart=/home/myusername/sites/pythonEnv/bin/gunicorn --bind unix:/tmp/mywebsite.socket /path/to/my/django/project.wsgi:application
But when I ran service gunicorn-mywebsite start, there was problem No module named '/path/to/my/django/project'.
If I run the same command my django project directory with relative path of my wsgi:application, it will work.
How can I fix this problem?
You can't give gunicorn a path to a file, it needs to be a module path, with application entry point name. So just project.wsgi:application. If the directory containing project is not in your path, then use the --pythonpath to gunicorn to tell it where it is.

OpenShift repo not included in path

I started a Django 1.7 OpenShift instance. When I have python print all of the paths from sys.path I do not see OPENSHIFT_REPO_DIR (/var/lib/openshift/xxxxx/app-root/runtime/repo).
When I use https://github.com/jfmatth/openshift-django17 to create a project I do see OPENSHIFT_REPO_DIR in the path.
Looking through the example app above I don't see anywhere that this is specifically added to the path. What am I missing?
To clarify:
I have to add the following to my wsgi.py:
import os
import sys
ON_PASS = 'OPENSHIFT_REPO_DIR' in os.environ
if ON_PASS:
x = os.path.abspath(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'mysite'))
sys.path.insert(1, x)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
OPENSHIFT_REPO_DIR is not in my path as I would expect. When I used the example git above, I did not have to add anything to the path.
A little while back I had issues with some of the pre-configured OpenShift environment variables not appearing until I restarted my application.
For what its worth, I started up a brand new Django gear, printed the environment variables to the application log, and verified that I do see OPENSHIFT_REPO_DIR (and all other env vars) properly.
This issue appears to be caused by trying to use the standard file structure layout that django produces when you use startproject. Openshift appears to need a flatter file structure. As soon as I moved wsgi up to a sibling of mysite it resolved the issue.

Simplest way to host html [duplicate]

This question already has answers here:
Best lightweight web server (only static content) for Windows [closed]
(8 answers)
Closed 8 years ago.
What is the simplest way to host an HTML page over LAN?
I literally just need to have like 5 lines of HTML, so I don't want to download and setup an Apache server. I just want to know the fastest/simplest way to do this on Windows, or I can also use one of my Linux virtual machines if it's faster.
Use netcat, or nc:
:top
nc -l -p 80 -q 1 < index.html
goto top
It's a simple binary without any installation. It doesn't do CGI or PHP or anything, but it can sure dish up 5 lines of HTML.
Actually, if you use the "k" (keep-alive) option you can remove the loop, and make it simpler:
nc -kl 80 < index.html
Since you need a web server for testing and no heavy concurrent use is expected, I'll just keep it simple.
Please note that both solutions are very simple but not very secure, use them for development purposes but don't rely on neither of them for anything barely similar to a stable (people would say "production") server.
Navigate to the directory where your HTML file is located using cmd.exe, then issue:
Using Python
python -m SimpleHTTPServer
A HTTP server will be started on port 8000. Should you need a different port, just specify it:
python -m SimpleHTTPServer 8080
SimpleHTTPServer is part of the "batteries included": you will not need to install any extra package, apart from the Python interpreter, of course.
Python comes already installed on most Linux distributions, so switching to Linux might be simpler than install Python on Windows, although that boils down to downloading and running an installer.
Using PHP 5.4 or above
php -S 0.0.0.0:8080
This will also process PHP scripts, but HTML resources will be served fine.
http://www.lighttpd.net/ is pretty light weight and easy to get running.
I recently used mongoose for a similar purpose. It supports Windows. From the homepage:
Mongoose executable does not depend on any external library or
configuration. If it is copied to any directory and executed, it
starts to serve that directory on port 8080. If some additional config
is required - for example, different listening port or IP-based access
control, then a mongoose.conf file with respective options (see
example) can be created in the same directory where executable lives.
This makes Mongoose perfect for all sorts of demos, quick tests, file
sharing, and Web programming.
Download the windows exe (no need to install) from here , save it on the folder where your html file is and execute it. Check the image below to know how to start the server:
After selecting Start Browser on Port 8080 your browser will open automatically displaying the contents of the folder.

openshift : need to edit httpd.conf to enable or add directive according to my needs but it's not work

i've build my application on localhost and running it without any error. i choose openshift to host my application code but i have a problem to make it works perfectly like on my localhost.
i want to add directive of AllowEncodedSlashes and set it to On in my apache2 configuration file, i have tried to edit the file from ~/php/configuration/etc/conf/httpd.conf and then restart the server using ctl_all restart. but the result are http error code 400 (Bad Request). before i add this directive into httpd.conf the result are http error code 404, i am just not sure if the changes are in effect or not. or apache is bugging?
is there anyone knows howto make this work for me?
See if you can add it into .htaccess file instead of httpd.conf file. Also the best way to troubleshoot these problems would be by reviewing your application logs for errors. All you have to do is run "rhc tail {appName}" from your client machine (where the rhc client tools are installed). That gives you the current log entries.
To get to the entire log, you'll want to ssh onto the gear(s) on which the language framework/cartridge is installed using this FAQ and run: more ~/{cartridgeID}/logs/*.log
where {cartridgeID} is your framework cartridge like nodejs-0.6, or your embedded cartridge logs like mysql-5.1.
I created a feature request for this. See this Trello card and feel free to vote it up.

JBoss - Moving the modules directory around

Wondering if it's possible to move the module directory in a JBoss 7 install to a non-default loco.
Does anyone know of a config param to specify where to pick it up?
Kinda like a conf-dir, bin-dir type of thing.
Thanks,
Aaron.
Yes, it's actually possible. As the documentation states, from within the standard launch scripts users are able to manipulate the module path by setting the $JBOSS_MODULEPATH environment variable. (If not set, $JBOSS_MODULEPATH is set to $JBOSS_HOME/modules). The module path is provided to the running process via the -mp command line argument that is set in the standard scripts.