nginx missing sites-available directory

后端 未结 3 1586
野趣味
野趣味 2020-12-04 04:31

I installed Nginx on Centos 6 and I am trying to set up virtual hosts. The problem I am having is that I can\'t seem to find the /etc/nginx/sites-available dire

相关标签:
3条回答
  • 2020-12-04 05:07

    If you'd prefer a more direct approach, one that does NOT mess with symlinking between /etc/nginx/sites-available and /etc/nginx/sites-enabled, do the following:

    1. Locate your nginx.conf file. Likely at /etc/nginx/nginx.conf
    2. Find the http block.
    3. Somewhere in the http block, write include /etc/nginx/conf.d/*.conf; This tells nginx to pull in any files in the conf.d directory that end in .conf. (I know: it's weird that a directory can have a . in it.)
    4. Create the conf.d directory if it doesn't already exist (per the path in step 3). Be sure to give it the right permissions/ownership. Likely root or www-data.
    5. Move or copy your separate config files (just like you have in /etc/nginx/sites-available) into the directory conf.d.
    6. Reload or restart nginx.
    7. Eat an ice cream cone.

    Any .conf files that you put into the conf.d directory from here on out will become active as long as you reload/restart nginx after.

    Note: You can use the conf.d and sites-enabled + sites-available method concurrently if you wish. I like to test on my dev box using conf.d. Feels faster than symlinking and unsymlinking.

    0 讨论(0)
  • 2020-12-04 05:20

    I tried sudo apt install nginx-full. You will get all the required packages.

    0 讨论(0)
  • 2020-12-04 05:23

    Well, I think nginx by itself doesn't have that in its setup, because the Ubuntu-maintained package does it as a convention to imitate Debian's apache setup. You could create it yourself if you wanted to emulate the same setup.

    Create /etc/nginx/sites-available and /etc/nginx/sites-enabled and then edit the http block inside /etc/nginx/nginx.conf and add this line

    include /etc/nginx/sites-enabled/*;
    

    Of course, all the files will be inside sites-available, and you'd create a symlink for them inside sites-enabled for those you want enabled.

    0 讨论(0)
提交回复
热议问题