Git Product home page Git Product logo

nginx-config-builder's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nginx-config-builder's Issues

config blocks are not generated in order

Hi,

I came across this library a couple of days ago and it's really helpful. However, I've got into an issue with the library not maintaining the order of config blocks. Some nginx configs are sensitive to their position in file. for e.g. 'log_format' that I use should be defined before it's used in access_log.

Any suggestion how to approach such issue?

Thanks

adding multiple server stanzas to an http block; bug?

In [1]: from nginx.config.api import Config, Section, Location, KeyOption, KeyValueOption, KeyMultiValueOption                                                                                        

In [2]: http = Section('http', include='../conf/mime.types')                                       

In [3]: server1 = Section('server', KeyValueOption('listen', '80'), KeyValueOption('server_name', 'server1.com'), KeyMultiValueOption('return', [301, 'https://$server_name$request_uri']))           

In [4]: server2 = Section('server', KeyValueOption('listen', '443'), KeyValueOption('server_name', 'server2.com'), KeyMultiValueOption('return', [302, 'https://$server_name$request_uri']))          

In [5]: http.sections.add(server1, server2)      

In [6]: http                                     
Out[6]: 

http {
    include ../conf/mime.types;
    server {
        listen 443;
        server_name server2.com;
        return 302 https://$server_name$request_uri;
    }
}

I then make a very small change to the code and run it again:

 sidler@76  ~  cd repos/scottidler/nginx-config-builder/src 
 sidler@76  ~/repos/scottidler/nginx-config-builder/src   master ●  git diff
diff --git i/src/nginx/config/api/options.py w/src/nginx/config/api/options.py
index 18f8945..0b6db52 100644
--- i/src/nginx/config/api/options.py
+++ w/src/nginx/config/api/options.py
@@ -116,7 +116,6 @@ class AttrDict(dict):
         self._owner = owner
         return ret
 
-
 class AttrList(AttrDict):
     """ A dictionary/list hybrid that exposes values as attributes. """
     def __iter__(self):
@@ -125,7 +124,7 @@ class AttrList(AttrDict):
     def append(self, item):
         if hasattr(item, '_parent'):
             item._parent = self._owner
-        if hasattr(item, 'name'):
+        if hasattr(item, 'name') and item.name != 'server':
             self[item.name] = item
         else:
             self[hash(item)] = item
 sidler@76  ~/repos/scottidler/nginx-config-builder/src   master ●  sudo -E ipython3
Python 3.7.5 (default, Nov 20 2019, 09:21:52) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.10.2 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from nginx.config.api import Config, Section, Location, KeyOption, KeyValueOption, KeyMultiValueOption                                                                                        

In [2]: http = Section('http', include='../conf/mime.types')                                       

In [3]: server1 = Section('server', KeyValueOption('listen', '80'), KeyValueOption('server_name', 'server1.com'), KeyMultiValueOption('return', [301, 'https://$server_name$request_uri']))           

In [4]: server2 = Section('server', KeyValueOption('listen', '443'), KeyValueOption('server_name', 'server2.com'), KeyMultiValueOption('return', [302, 'https://$server_name$request_uri']))          

In [5]: http.sections.add(server1, server2)      

In [6]: http                                     
Out[6]: 

http {
    include ../conf/mime.types;
    server {
        listen 80;
        server_name server1.com;
        return 301 https://$server_name$request_uri;
    }
    server {
        listen 443;
        server_name server2.com;
        return 302 https://$server_name$request_uri;
    }
}

It seems what is happening here is that it tests to see if the object as a 'name' field and if so, it uses this for the hash of the dictionary. In the case of the server blocks, the 'name' field is 'server' and therefore it only allows for one server block. Is this intentional? Is this a bug? Or is there another way that this is supposed to be used?

how to parse current config?

my usecase: change existing nginx config (add upstream, change location, add server block)

how i can achieve it?

multiple options in sections

common use case for reverse proxy is the following config:

server {
    add_header Strict-Transport-Security max-age=31536000;
    location /api/v1 {
        proxy_pass http://127.0.0.1/;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

I mean proxy_set_header options.
How i can achieve it with this library?

Repeated keywords support

Hello, I'm trying to define some add_header directives but I can't because the system detects it like repeated keyword, is possible to solve this?

Best!

about upstreams

thx for this nginx tool,
can nginx-config-builder support config of upstreams?
thx very much

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.