nginx 404 not found, how to config https in nginx.conf ?

Posted March 1, 2020 2k views

I set up a static website through nginx, firewall closed and authorization is granted, I type “nginx -t”, this message is returned:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
it prompt 404 not found,and generates no errors in errorlog,
the same configuraiton runs well on another vps.

What is the problem?

****configuration is below:

user root;
worker_processes 4;
pid /run/;

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;

    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/*;

    index index.htm index.html;
    server {
        listen  443 ssl;
        server_name www.XXX.XXX;
        root /var/www/display;
        ssl_certificate       /etc/v2ray/v2ray.crt;
        ssl_certificate_key   /etc/v2ray/v2ray.key;
        ssl_protocols         TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers           HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;

        location /{ 
        proxy_redirect off; 
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;

        # Show realip in v2ray access.log
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    server {
        listen       80;
        server_name  www.XXX.XXX;
        return 301 https://$server_name$request_uri;
edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there @pragvisionary.

The configuration actually looks correct to me. When you get the 404 error, do you also see that entry in the Nginx access log?

I could suggest a couple of things:

  • Try visiting your backend service directly on its port and see if it is returning any results

  • Make sure that your domain name is actually pointing to the Droplet. You could check that with the ping command:

  • ping
  • Try adding your non-www version to your server_name list as well:

Let me know how it goes!