How to solve the Nginx error on digitalocean

129 views
Skip to first unread message

Maurice Waka

unread,
Jul 15, 2019, 7:45:10 AM7/15/19
to web2py-users
I have a usual 'working' nginx file which works fine when being tested.

The /etc/nginx/nginx.conf file

user www-data;
worker_processes
auto;
pid
/run/nginx.pid;
include
/etc/nginx/modules-enabled/*.conf;


events {
        worker_connections 768;
        # multi_accept on;
}


http {


        ##
        # Basic Settings
        ##


        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;


        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;


        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        ##
        # SSL Settings
        ##


        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;


        ##
        # Logging Settings
        ##


        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;


        ##
        # Gzip Settings
        ##


        gzip on;


        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


But when edited with the server details below, I get this error nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:90
nginx: configuration file /etc/nginx/nginx.conf test failed.

How do I overcome this??

server {
    listen 443;
    server_name server_domain_or_IP;

    root html;
    index index.html index.htm;

    ssl on;
    ssl_certificate /etc/nginx/ssl/myapp.crt;
    ssl_certificate_key /etc/nginx/ssl/myapp.key;

    ssl_session_timeout 5m;

    #ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
    ssl_prefer_server_ciphers on;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/user/myapp/myapp.sock;
    }
}


Jim S

unread,
Jul 15, 2019, 9:39:27 AM7/15/19
to web2py-users
I don't think server can be a root element in this file.  Do you have it under another element?  I'd try it like this:

web2py {

    server
{
        listen
443;
        server_name server_domain_or_IP
;


        root html
;
        index index
.html index.htm;


        ssl on
;
        ssl_certificate
/etc/nginx/ssl/myapp.crt;
        ssl_certificate_key
/etc/nginx/ssl/myapp.key;


        ssl_session_timeout
5m;


       
#ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_protocols
TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers
"HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
        ssl_prefer_server_ciphers on
;


        location
/ {
            include uwsgi_params
;
            uwsgi_pass unix
:/home/user/myapp/myapp.sock;
       
}
   
}
}

Also, you can look in the book:


There are good references there on how to setup nginx with uwsgi on ubuntu.

-Jim

Maurice Waka

unread,
Jul 16, 2019, 4:01:02 AM7/16/19
to web2py-users
Used the link as you directed

posted this:
# file /etc/nginx/sites-available/web2py
server {
        listen          80;
        server_name     165.22.57.107;
        #to enable correct use of response.static_version
        #location ~* /(\w+)/static(?:/_[\d]+.[\d]+.[\d]+)?/(.*)$ {
        #    alias /web2py/applications/$1/static/$2;
        #    expires max;
        #}
        location ~* /(\w+)/static/ {
            root /web2py/applications/;
            #remove next comment on production
            #expires max;
        }
        location / {
            #uwsgi_pass      127.0.0.1:8000;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
        }
}
server {
        listen 443 default_server ssl;
        server_name     165.22.57.107;
        ssl_certificate         /etc/nginx/ssl/web2py.crt;
        ssl_certificate_key     /etc/nginx/ssl/web2py.key;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
        ssl_protocols SSLv3 TLSv1;
        keepalive_timeout    70;
        location / {
            #uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
        }

}


But got this error:

nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:86


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/rEu_Yc91LVY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/d88f1ae3-40aa-44ac-a365-7b97995b81da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jim Steil

unread,
Jul 16, 2019, 7:38:01 AM7/16/19
to web...@googlegroups.com
Did you take that server directive out of the nginx.conf file?

Jim


Maurice Waka

unread,
Jul 16, 2019, 9:16:57 AM7/16/19
to web2py-users
Nope. Web2py example 

Jim Steil

unread,
Jul 16, 2019, 9:28:27 AM7/16/19
to web...@googlegroups.com
I would remove that and retry it.

Maurice Waka

unread,
Jul 16, 2019, 10:12:53 AM7/16/19
to web2py-users
removed, tried, restarted everything but errors still remains.
Modified it as you had suggested but the latest error:
nginx: [emerg] unknown directive "web2py" in /etc/nginx/nginx.conf:87

Jim S

unread,
Jul 16, 2019, 10:26:14 AM7/16/19
to web2py-users
No, I'd just remove all of that completely.  This is my production nginx.conf file.  Also note the last 2 lines...

user www-data;
worker_processes
auto;
pid
/run/nginx.pid;



events
{

 worker_connections
768;
 
# multi_accept on;
}


http
{


 
##
 
# Basic Settings
 
##


 sendfile on
;
 tcp_nopush on
;
 tcp_nodelay on
;

 keepalive_timeout
65;
 types_hash_max_size
2048;
 
# server_tokens off;


 
# server_names_hash_bucket_size 64;
 
# server_name_in_redirect off;


 include
/etc/nginx/mime.types;
 default_type application
/octet-stream;


 
##
 
# SSL Settings
 
##


 ssl_protocols
TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
 ssl_prefer_server_ciphers on
;


 
##
 
# Logging Settings
 
##


 access_log
/var/log/nginx/access.log;
 error_log
/var/log/nginx/error.log;


 
##
 
# Gzip Settings
 
##


 gzip on
;

 gzip_disable
"msie6";


 
# gzip_vary on;
 
# gzip_proxied any;
 
# gzip_comp_level 6;
 
# gzip_buffers 16 8k;
 
# gzip_http_version 1.1;
 
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;


 
##
 
# Virtual Host Configs
 
##


 include
/etc/nginx/conf.d/*.conf;
 include /etc/nginx/sites-enabled/*;
}


-Jim

Nope. Web2py example 

To unsubscribe from this group and all its topics, send an email to web...@googlegroups.com.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/rEu_Yc91LVY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web...@googlegroups.com.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/rEu_Yc91LVY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web...@googlegroups.com.

Maurice Waka

unread,
Jul 17, 2019, 2:07:32 AM7/17/19
to web2py-users
Hi I searched and found a good step by step directive from this.

But the server directive was this:

OK, looking closer into the web2py email list that I linked above, I figured out that the copmlete solution is already there. I could follow the instructions and, thanks pbreit's brilliant post, now my deployment works like a charm (using only 38MB RAM in idle state) with nginx+uwsgi.

Here are the parts that I used (I just stripped down the fabfile.py to use it on command line) Note: where there is 'put('....' I used nano text editor to create and edit files

apt-get -y install build-essential psmisc python-dev libxml2 libxml2-dev python-setuptools
cd /opt; 
wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar -zxvf uwsgi*
mv /opt/uwsgi*/ /opt/uwsgi/
cd /opt/uwsgi/; python setup.py install
chown -R www-data:www-data /opt/uwsgi
touch /var/log/uwsgi.log
chown www-data /var/log/uwsgi.log
apt-get -y install libpcre3-dev build-essential libssl-dev
cd /opt; wget http://nginx.org/download/nginx-0.8.54.tar.gz
cd /opt; tar -zxvf nginx*
cd /opt/nginx*/; ./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module
cd /opt/nginx*/; make
cd /opt/nginx*/; make install
adduser --system --no-create-home --disabled-login --disabled-password --group nginx
cp /opt/uwsgi*/nginx/uwsgi_params /opt/nginx/conf/uwsgi_params

wget https://library.linode.com/web-servers/nginx/installation/reference/init-deb.sh
mv init-deb.sh /etc/init.d/nginx

chmod +x /etc/init.d/nginx
/usr/sbin/update-rc.d -f nginx defaults
/etc/init.d/nginx start

cd /opt/
wget https://library.linode.com/web-servers/nginx/python-uwsgi/reference/init-deb.sh
mv /opt/init-deb.sh /etc/init.d/uwsgi
chmod +x /etc/init.d/uwsgi

echo 'PYTHONPATH=/var/web2py/ MODULE=wsgihandler' >> /etc/default/uwsgi
/usr/sbin/update-rc.d -f uwsgi defaults
/etc/init.d/uwsgi start


rm /opt/nginx/conf/nginx.conf
# modify nginx.conf below and save it as /opt/nginx/conf/nginx.conf
cd /opt/nginx/conf; openssl genrsa -out server.key 1024
cd /opt/nginx/conf; openssl req -batch -new -key server.key -out server.csr
cd /opt/nginx/conf; 
openssl x509 -req -days 1780 -in server.csr -signkey server.key -out server.crt

/etc/init.d/nginx restart 

nginx.conf

     user www-data;
     worker_processes  4;

     events {
         worker_connections  1024;

     }

     http {
         include       mime.types;
         default_type  application/octet-stream;
         keepalive_timeout  2;
         sendfile        on;
         #tcp_nopush     on;
         tcp_nodelay     on;
         gzip  on;
         server {
             listen       80;
             server_name  example.com www.example.com;

             location / {
                 uwsgi_pass 127.0.0.1:9001;
                 include uwsgi_params;
             }

             location /static {
                 root /var/web2py/applications/init/;
             }
         }

  # HTTPS server
     server {
         listen       443;
         server_name  www.example.com example.com;
         ssl                  on;
         ssl_certificate      /opt/nginx/conf/server.crt;
         ssl_certificate_key  /opt/nginx/conf/server.key;

         location / {
             uwsgi_pass 127.0.0.1:9001;

             include uwsgi_params;
             uwsgi_param     UWSGI_SCHEME $scheme;
         }



   location /static {
             root /var/web2py/applications/init/;
         }
     }

 }
And the test was successful.
Regards

To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/d29b978d-c486-4ae1-921e-64aa463c989e%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages