0

This is my /etc/nginx/sites-enabled/default file

map $sent_http_content_type $expires {
    default                    off;
    text/html                  epoch;
    text/css                   30d;
    application/javascript     30d;
    ~image/                    max;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        expires $expires;
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
        root /home/ubuntu/ask-local-django;

        # Add index.php to the list if you are using PHP
        #index index.html index.htm index.nginx-debian.html;

        server_name api.example.in admin.example.in;

        #location /favicon.ico { access_log off; log_not_found off; }

        location /media {
                autoindex on;
                alias /home/ubuntu/ask-local-django/media/;
        }

        location /static {
                access_log off;
                log_not_found off;
                alias /home/ubuntu/ask-local-django/staticfiles;
        }

#        location /.well-known {
 #               alias /home/ubuntu/ask-local-django/well-known;
  #      }

        location / {
                include proxy_params;
                proxy_pass http://unix:/run/gunicorn.sock;
        }
        #location /.wellness/assetlink.json {
         #       root /home/ubuntu/ask-local-django/static/;
       # }


        access_log /home/ubuntu/logs/ask_local_access.log;
        error_log /home/ubuntu/logs/ask_local_error.log;

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}


server {

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        expires $expires;

        # include snippets/snakeoil.conf;
        client_max_body_size 10M;
        root /home/ubuntu/ask-local-django;

        # Add index.php to the list if you are using PHP
        #index index.html index.htm index.nginx-debian.html;
        server_name api.example.in admin.example.in; # managed by Certbot
        location  /media {
           autoindex on;
           alias  /home/ubuntu/ask-local-django/media;
        }
        location /favicon.ico { access_log off; log_not_found off; }
        location /static {
                alias /home/ubuntu/ask-local-django/static;
        }
        location /.well-known {
                alias /home/ubuntu/ask-local-django/well-known;
        }

        location / {
                include proxy_params;
                proxy_pass http://unix:/run/gunicorn.sock;
        }

        access_log /home/ubuntu/logs/ask_local_access.log;
        error_log /home/ubuntu/logs/ask_local_error.log;


        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}


    #listen [::]:443 ssl ipv6only=on; # managed by Certbot
    #listen 443 ssl; # managed by Certbot
    #ssl_certificate /etc/letsencrypt/live/api.asklokal.com/fullchain.pem; # managed by Certbot
    #ssl_certificate_key /etc/letsencrypt/live/api.asklokal.com/privkey.pem; # managed by Certbot
    #include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    #ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = admin.example.in) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = api.example.in) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    return 404; # managed by Certbot
}

This is my /etc/nginx/nginx.conf

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
        ##
        client_max_body_size 10M;
        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_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/*;
}

#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

My nginx configuration syntax looks ok

#sudo nginx -t

nginx: [warn] conflicting server name "api.example.in" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "admin.example.in" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

My nginx error logs shows

2024/04/16 15:22:21 [emerg] 3741#3741: "map" directive is not allowed here in /etc/nginx/sites-enabled/default:1
2024/04/16 15:30:40 [warn] 3777#3777: conflicting server name "api.example.in" on 0.0.0.0:80, ignored

And I am getting http response code of 500.

It started when I modified my server_name from example.com to aaa.com and then again modifying back to example.com. It is working previously without any issues.

1
  • How are you starting Nginx? I would expect the error log to be the same as nginx -t, unless you are staring Nguni with a -c. Commented Apr 17, 2024 at 7:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.