简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM