Real-Gecko / virtualmin-nginx-fpm

Virtualmin plugin to create Nginx and PHP-FPM powered websites for domains
GNU General Public License v3.0
24 stars 9 forks source link

Base code and room for improvment #7

Open sinasalek opened 8 years ago

sinasalek commented 8 years ago

I check the source code of the module, and it seems that you have started almost from scratch. So i was wondering why you haven't used source code of nginx-webmin module or Apache module. https://github.com/vixh/nginx-webmin https://github.com/lewellyn/virtualmin-nginx

sinasalek commented 8 years ago

I just installed virtualmin nginx module according to https://www.virtualmin.com/documentation/web/nginx With a quick comparison, there are some important features the it offers comparing to this module :

  1. In Services -> PHP 5 Configuration, it's possible to manage php configuration easily via UI. this option is not available when virtualmin-nginx-fpm is used
  2. Logs and reports -> Nginx Access Log & Nginx Error Log
  3. Server Configuration -> Website Options which is available with virtualmin-nginx-fpm but with much less settings.
  4. Server Configuration -> Website Redirects
Real-Gecko commented 8 years ago

Initially I planned to create module that only manages FPM. But lurking through the core Nginx module code revealed that adding new PHP execution mode will require it's modification. So I created module that manages both Nginx and FPM configs for domains. For now it fits my needs completely, however there's always room for improvements. So let's see:

  1. What PHP options do you exactly need to manage?
  2. Yep, missed that :)
  3. Did not get what're you trying to say.
  4. Maybe if I understood how it works :D
sinasalek commented 8 years ago

Thanks for the quick response.

  1. PHP settings. i attached a screenshot (this is important because end users can't modify php.ini directly they need a simple UI to do that). it looks like virtualmin default php settings page per domain, , so i think nginx module simple lets virtualmin know that php is active for the domain, it might actually be quite easy to activate that page, not sure thought. php settings
  2. Attached another image, in this page i can change log files path. change script max run time, etc website options
  3. Lets you redirect some URLs to another URLs website redirects
Real-Gecko commented 8 years ago
  1. FPM does not support per pool php.ini configuration. Some variables can be set in pool ini, but not all. http://php.net/manual/en/install.fpm.configuration.php So, no luck here.

2 and 3 need investigation.

sinasalek commented 8 years ago
  1. i played with it quite some time ago, i'll see if i can find a workaround
sinasalek commented 8 years ago

Found it :) http://php.net/manual/en/configuration.file.per-user.php

Real-Gecko commented 8 years ago

In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned. Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files. Discussion goes nowhere, let's talk about what you really need. What settings you really need to be defined?

sinasalek commented 8 years ago

Well what i need is to let the user modify php settings per virtualhost via UI the way the he can when apache or nginx module is used

Real-Gecko commented 8 years ago

Well if we talk about this http://php.net/manual/en/configuration.file.per-user.php, then this typo of files can be easily created and modified through built in filemanager :D I never used this option, so if we wanna provide interface for such tasks then it requires some more investigation and some time to develop :)))

sinasalek commented 8 years ago

Sure it does, just wanted to put it out there in case you were interested :)

Real-Gecko commented 8 years ago

Yep, making module better is a good thing :) I'll see what can be done to add feature you request. Any particular settings are required now? Would be a great opportunity to start adding and testing :)

sinasalek commented 8 years ago

Thanks, that would be great :) I'm setting up two new servers using your module, both require modification of generated nginx config for the web applications to work properly, since there is no way to do it in a non hackish way using the module. I've mentioned this on another issue earlier as you know. I think this is probably the most important feature that many will need including myself. I'll send more feedback if i encounter any major limitation.

Real-Gecko commented 8 years ago

What CMS you use for your two servers? Did you try default config?

sinasalek commented 8 years ago

One of the applications is a custom frameworks that required lots of custom configs. No way to make it generic :). The others are Moodle and Magento, the default config works just fine but they both had some additional customization in their .htaccess that needed to be ported to nginx. Check this out :

# bad request
error_page 400 = /errorDocuments/badRequest.html;
# Authorization Required‎
error_page 401 = /errorDocuments/authorizationRequired.html;
# access forbidden
error_page 403 = /errorDocuments/accessForbidden.html;
# document not found
error_page 404 = /errorDocuments/pageNotFound.html;
# internal server error
error_page 500 = /errorDocuments/maintenance.html;

# enable gzip compression
gzip on;
gzip_min_length  1100;
gzip_buffers  4 32k;
gzip_types    text/plain text/xml text/css application/x-javascript application/xml application/xhtml+xml application/rss+xml application/javascript;
gzip_proxied    no-cache no-store private expired auth;
gzip_vary on;
# end gzip configuration

autoindex on;

# (Begin) Protect files and directories from prying eyes.
location ~ \.(test|sql|bak)$|^(development|documents|old|garbage|docs|test|delete)$ {
    deny all;
}
# (End) Protect files and directories from prying eyes.

location ~ \.(js|css|png|jpg|jpeg|gif|ico|html|woff|ttf|svg|eot|otf)$ {
    valid_referers none blocked ~.facebook. ~.google. ~.fb. ~.friendfeed. ~.yahoo. ~.bing. ~.feedreader. ~.feedly. server_names ~($host);
    if ($invalid_referer) {
        rewrite .*\.(jpe?g|bmp|png)$ /hotlink.gif redirect; 
    }

    add_header "Access-Control-Allow-Origin" "*";
    expires 1M;
    access_log off;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    gzip_static on;

        proxy_hide_header       Set-Cookie;
    proxy_ignore_headers    Set-Cookie;
    # important! Remember the special inheritance rules for proxy_set_header:
    # http://nginx.org/ru/docs/http/ngx_http_proxy_module.html#proxy_set_header
    proxy_set_header        Cookie "";
            fastcgi_param PHP_VALUE "session.use_cookies=0";
    fastcgi_hide_header Set-Cookie;
}
# stop hotlink loop
location = /hotlink.gif { }
# BEGIN REQUIRED FOR WEBFONTS AND static file cache

index index.php index.html index.htm;

location /forum {
    rewrite ^(.*)$ http://forum.example.com redirect;
}
location /favicon { rewrite ^/favicon\.ico$ /view/themes/default/images/favicon.ico break; }
location /sitemap { rewrite ^/sitemap\.xml$ /view/model/sitemap.xml.php break; }
location /robots { rewrite ^/robots\.txt /view/model/robots.txt break; }
location /rss { rewrite ^(.*)$ /view/model/rss.php?mode=full break; }
location cache { }
location ~ ^/(.*/)?files\/printablePhotos\/*/ { return 403; }

#--(Begin)-- Redirect old paths
location /form { rewrite ^/form/(.+)$ /files/extform/$1 redirect; }
#--(End)-- Redirect old paths

location / {
    rewrite /(files/blogSystem/.*)$ http://blogs.example.com/$1 redirect;
    # This is cool because no php is touched for static content
    try_files $uri @rewrite;
}

location @rewrite {
    if ($http_host ~ "^class\.example\.com$"){ rewrite ^/tweet(.*)$ /twitter/class$1 last; }
    if ($http_host ~ "^class\.example\.com$"){ rewrite ^/$ /sn/siteStaticPages/id/3 last; }
    if ($http_host !~ "class\.example\.com"){ rewrite ^/sn/siteStaticPages/id/3$ http://class.example.com redirect; }       
    if ($http_host ~ "^print\.example\.com$"){ rewrite ^/$ /sn/printLandingPage last; }

    rewrite .*news/archives/(.*)$ http://newsarchive.example.com/news/archives/$1 redirect;
    rewrite (news/[^/]+)/full$ /$1 redirect;
    rewrite ((news|articles)/[^/]+)/$ /$1 redirect;

    rewrite ^/panel/cn/([^/]*)?(.*)$ /panel/model/$1.php?qs=$2& last;
    rewrite ^/panel/?(.*)$ /panel/index.php?qs=$1 last;
    rewrite ^/cn/([^/]*)?(.*)$ /model/$1.php?qs=$2& last;
    rewrite ^/(.*)$ /index.php?qs=$1;
}

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    try_files $uri =404;
    include     nginx.fastcgi.conf;
    fastcgi_pass    php_farm;
}
Real-Gecko commented 8 years ago

As far as I can see theese are configs ready to be used by Nginx. I just got some interesting idea: what if I add some textarea in Virtualmin domain management, that is inserted inside the Nginx config server block later? So user will be able to add some additional settings to already existing config. Just a quick solution that might work.

sinasalek commented 8 years ago

Yes that would be a very good quick solution.