m4jesticsun
m4jesticsun

Reputation: 2009

python + nginx internal server error

So I've setup my server following this tutorial: http://jronnholm.sysio.se/setup-nginx-and-uwsgi-with-python3-on-ubuntu-14-04/

See: nginx + uwsgi + python3 configuration not working

I managed to get it to work by switching /etc/nginx/sites-available/default with /etc/nginx/sites-available/pythonapp and change the sitename to _.

My /etc/nginx/sites-available/default:

server {
    server_name _;
    error_log  /var/log/nginx/pythonapp.error.log;
    access_log         /var/log/nginx/pythonapp.access.log;
    root /vagrant/site/python/pythonapp;
    location / {
        uwsgi_pass unix:/var/run/uwsgi/app/pythonapp/socket;
        include uwsgi_params;
    }
}

But then when I change the content of webpage.py to this:

print "Content-type: text/html\n\n"
print("lololol");

It ends up returning internal server error when I go to http://localhost:8080.

What did I do wrong?

Upvotes: 0

Views: 299

Answers (1)

Roald Nefs
Roald Nefs

Reputation: 1412

The Python code of your webpage.py is invalid. Try running it directly from the command line: python3 webpage.py will show you what is wrong.

Change your webpage.py to:

print("Content-type: text/html\n\n")
print("lololol")

The print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement (PEP 3105).

Note I've removed the semicolon from the second line because it is not doing anything in your example. Python does not require semi-colons to terminate statements. Semicolons can be used to delimit statements if you wish to put multiple statements on the same line.

Upvotes: 1

Related Questions