How to Fix No default.conf file in conf.d after Installing Nginx

In the process of learning nginx, the default.conf file in the conf.d directory cannot be found after installing nginx. The reason is that the EPEL source under the operating system is downloaded by default, which is the Fedora operating system

Scheme I

resolvent

Reinstall nginx and modify the EPEL image source address of nginx

Reinstall

sudo yum install yum-utils

Create a new nginx.repo file

sudo vim /etc/yum.repos.d/nginx.repo

add to

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

By default, a stable repository of nginx packages is used. If you want to use the mainline nginx package, run the following command:

sudo yum-config-manager --enable nginx-mainline

Installing nginx

sudo yum install nginx

This is the information I found on the Internet. I see that many people have handled this problem according to this scheme, but like me, there is still no default.conf file under scheme 1 conf.d, so you can try the second method.

Scheme II

Because the default.conf itself is a configuration file, my idea is to directly create one since there is no one, and see if it works. So I created an empty file with VI default.conf, and then found the contents of the default.conf file on the Internet and put it in.

server {
    listen       80;
    server_name  localhost;


    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location /mystatus {
        stub_status;
    }

    location/{
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }


    #error_page  404              /404.html;


    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  404 /50x.html;//Modify the 404 status code of the corresponding pointed to the access directory, and restart the server after modification.
    location = /50x.html {
        root   /usr/share/nginx/html;
    }


    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}


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

Finally, we changed the configuration according to the project requirements we deployed. Let’s also start nginx to have a look. We can see that there is no error after starting nginx, and we can also see the process of nginx, which shows that this method is feasible and simpler than scheme 1.


Read More: