nginx Windows: setting up sites-available configs

后端 未结 4 1040
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 15:49

I\'m trying to set up Nginx on my Windows development environment. I can\'t find how to create something similar to \"sites-enabled\" on Linux where Nginx would

相关标签:
4条回答
  • 2020-12-08 16:23

    The "sites-enabled" approach as used by some Linux packages of nginx utilize include directive, which understands shell wildcards, see http://nginx.org/r/include. You may use it in your own config as well, e.g.

    http {
        ...
        include /path/to/sites/*.conf;
    }
    

    Note though that such approach might be very confusing (in particular, it would be hard to tell which server{} is the default one unless you use default_server explicitly).

    0 讨论(0)
  • 2020-12-08 16:27

    The following worked for me but only AFTER I moved my main nginx exe folder from c:/Program Files (x86)/nginx-1.7.0 to c:/nginx-1.7.0 (because I think it doesn't handle spaces in file paths well):

    http {
        ...
        include "f:/code/mysite/dev-ops/nginx/dev/mysite.conf";
    }
    
    0 讨论(0)
  • 2020-12-08 16:36

    You can include your config with a relative path in your nginx.config (the relative path is just the path of the config file itself in contrast to the logs path for example):

    http {
      include       mime.types;
      default_type  application/octet-stream;
      include       ../sites-enabled/*.conf;
      ...
    }
    
    0 讨论(0)
  • 2020-12-08 16:38

    In windows you have to give full path of the directory where the config files are located. There are two files to update: nginx.conf, which tells nginx where to find web sites, and localhost.conf, which is the configuration for a web site.

    It is assumed that nginx is installed in C:\nginx. If the installation directory is at another path, you will have to update that path accordingly, wherever it appears in the following two configuration files.

    nginx.conf

    Location: C:\nginx\conf

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        #to read external configuration.
        include "C:/nginx/conf/sites-enabled/*.conf";
    }
    

    localhost.conf

    Location: C:\nginx\conf\sites-enabled

    server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    }
    
    0 讨论(0)
提交回复
热议问题