Mostra notizie nelle discussioni
  • Avatar
    ☺
    Scritto da
    il 2017-07-30 20:11:06.0 alle 2017-07-30 20:11:06.0
    Trollate totali: 6369
    nginx server block, aka virtualhosts + php-fpm unix socks = 403
    dunqve, non ho voglia di mettermi li e fare virtual machines per testare se fail2ban+ipset configurato come ce l'ho andrebbe in un vps normale,sono abbastanza convinto di si ma prima di prendere uno o piu' kvm per potermi mettere il cuore in pace e bannare a volonta' i falliti voglio finire il playbook, che sta venendo piuttosto bene, da una centos 7 minimal devo solo accedere una volta, configurare un user con sudo e poi copiarci le mie chiavi dal laptop con ssh-copy-id, dopodiche' avvio il playbook e installa LEMP, fail2ban, firewall, etc.
    queste sono le sezioni:

       roles: 
        - common
        - hardening
        - mariadb
        - nginx
        - php-fpm
        - wordpress
        - mediawiki
    


    vanno tutte, ho automatizzato pure l'installazione di mediawiki e quello che voglio ottenere e' un nginx che serva wordpress e mediawiki a questi indirizzi:

    vpshostingip:port1
    vpshostingip:port2

    il playbook da cui sono partito conteneva installava php-fpm e wordpress configurando i socks cosi:
    cat /etc/php-fpm.d/wordpress.conf
    
    [wordpress]
    listen = /var/run/php-fpm/wordpress.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0660
    user = wordpress
    group = wordpress
    pm = dynamic
    pm.max_children = 10
    pm.start_servers = 1
    pm.min_spare_servers = 1
    pm.max_spare_servers = 3
    pm.max_requests = 500
    chdir = /srv/wordpress/
    php_admin_value[open_basedir] = /srv/wordpress/:/tmp
    

    il playbook ha questo aspetto qui:

    - name: Disable default pool
      command: mv /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.disabled creates=/etc/php-fpm.d/www.disabled
      notify: restart php-fpm
      tags: php-fpm
    
    - name: Config php-fpm UNIX socket for wordpress.conf in php-fpm.d
      template: src=wordpress.conf dest=/etc/php-fpm.d/
      notify: restart php-fpm
      tags: php-fpm
    


    che dite se replico tutto per mediawiki cambiando solo il nome? dovro farne uno anche per mediawiki no? anche non ho piu' i calzini di default per php-fpm. (il playbook da cui sono partito e' uno degli esempi completi che ti viene fornito nella documentazione, lo ho modificato un po ma questo coso installava wordpress cosi, e me ne sono accorto solo ora


    [webserver@1024 ~]$ ls -la /var/run/php-fpm/
    total 4
    drwxr-xr-x  2 root  root   80 29 lug 01.11 .
    drwxr-xr-x 24 root  root  580 30 lug 17.24 ..
    -rw-r--r--  1 root  root    5 29 lug 01.11 php-fpm.pid
    srw-rw----  1 nginx nginx   0 29 lug 01.11 wordpress.sock
    


    quindi dovrei farne uno anche per mediawiki?
    l'installazine di mediawiki la ho fatto brutalmente cosi:

    mediawiki role in playbook:

    ---
    - name: Download Mediawiki
      get_url: 
       url=https://releases.wikimedia.org/mediawiki/1.29/mediawiki-1.29.0.tar.gz 
       dest=/srv/
      tags: mediawiki
    
    - name: Extract archive
      unarchive: 
       src=/srv/mediawiki-1.29.0.tar.gz 
       dest=/srv/mediawiki
       remote_src=True
      tags: mediawiki
    
    - name: Add group "mediawiki"
      group: name=mediawiki
      tags: mediawiki
    
    - name: Add user "mediawiki"
      user: name=mediawiki group=mediawiki home=/srv/mediawiki/
      tags: mediawiki
    
    - name: Create MediaWiki database
      mysql_db: name={{ mw_db_name }} state=present login_password=
      tags: mediawiki
    
    - name: Create Mediawiki database user
      mysql_user: 
       name={{ mw_db_user }} 
       password={{ mw_db_password }} 
       priv={{ mw_db_name }}.*:ALL 
       host='localhost' 
       login_password=
       state=present
      tags: mediawiki
    
    - name: Change ownership of MediaWiki installation path
      file: path=/srv/mediawiki/ owner=mediawiki group=mediawiki state=directory recurse=yes
      tags: mediawiki
    
    - name: Start php-fpm Service
      service: name=php-fpm state=started enabled=yes
      tags: mediawiki
    
    - name: Start NGINX Service
      service: name=nginx state=started enabled=yes
      tags: mediawiki


    e se lancio il playbook completo il risultato e' buono, perche' wordpress va come dovrebbe, e' raggiungibile all'indirizzo

    vpshostingip:port1

    ma mediawiki invece al suo bell'indirizzo

    vpshostingip:port2

    mostra solo un 403 forbidden.

    nginx.conf
    conf.d/
           wordpress.conf
           mediawiki.conf


    cat nginx.conf
    
    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/
    
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    
    # Load dynamic modules. See /usr/share/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
    # Hardening settings found on the internet
        server_tokens off;
    # useless for now 
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        # Load modular configuration files from the /etc/nginx/conf.d directory.
        # See http://nginx.org/en/docs/ngx_core_module.html#include
        # for more information.
        include /etc/nginx/conf.d/*.conf;
    


    cat wordpress.conf
    server {
            listen       {{ nginx_wordpress_port }};
            server_name  {{ server_hostname }};
            root /srv/wordpress/;
     
    	client_max_body_size 64M;
     
    	# Deny access to any files with a .php extension in the uploads directory
            location ~* /(?:uploads|files)/.*\.php$ {
                    deny all;
            }
     
            location / {
                    index index.php index.html index.htm;
                    try_files $uri $uri/ /index.php?$args;
            }
     
            location ~* \.(gif|jpg|jpeg|png|css|js)$ {
                    expires max;
            }
     
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_index index.php;
                 fastcgi_pass  unix:/var/run/php-fpm/wordpress.sock;
                    fastcgi_param   SCRIPT_FILENAME
                                    $document_root$fastcgi_script_name;
                    include       fastcgi_params;
            }
    }
    


    cat mediawiki.conf
    server {
        listen      {{ nginx_mediawiki_port }};
        server_name {{ server_hostname }};
        root /srv/mediawiki;
    
        client_max_body_size 5m;
        client_body_timeout 60;
    
        location / {
            try_files $uri $uri/ @rewrite;
        }
    
        location @rewrite {
            rewrite ^/(.*)$ /index.php?title=$1&$args;
        }
    
        location ^~ /maintenance/ {
            return 403;
        }
    
        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/phpfpm.sock;
        }
    
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            try_files $uri /index.php;
            expires max;
            log_not_found off;
        }
    
        location = /_.gif {
            expires max;
            empty_gif;
        }
    
        location ^~ /cache/ {
            deny all;
        }
    
        location /dumps {
            root /srv/mediawiki/local;
            autoindex on;
        }
    }
    


    pecche se visito la pagina di mediawiki mi dice che e' proibito?
    e' davvero colpa del calzino php-fpm?

    **Modificato dall'autore il 30.07.2017 20:20**
    Please consider the environment before printing this message, 50% of the above is useless!
    • Avatar
      ☺
      Scritto da
      il 2017-07-30 20:34:32.0 alle 2017-07-30 20:34:32.0
      Trollate totali: 6369
      Re: nginx server block, aka virtualhosts + php-fpm unix socks = 403
      nope, non era quello.
      ho messo il socks modificando il playbook ci vuole veramente un cazzo a fare tutto cio, cambioi file nel template e poi rifaccio andare ansible, fa l'md5 di tutto, se qualcosa e' cambiato nel template allora rifa l'operazione, senno no.
      ho modificato il role che installa php==fpm per fare un sock anche per mediawiki ma non e' cambiato nulla, sempre 403 proibito sulla porta dove dovrebbe esserci mediawiki mentre wordpress va

      $ ls -la /var/run/php-fpm/
      total 4
      drwxr-xr-x  2 root  root  100 30 lug 18.29 .
      drwxr-xr-x 24 root  root  580 30 lug 18.29 ..
      srw-rw----  1 nginx nginx   0 30 lug 18.29 mediawiki.sock
      -rw-r--r--  1 root  root    5 30 lug 18.29 php-fpm.pid
      srw-rw----  1 nginx nginx   0 30 lug 18.29 wordpress.sock
      


      e' colpa di nginx, devo aver configurato male qualcosa e secondo lui sto facendo le cosacce, so che non e' il firewall ne l'os perche' lo raggiungo e capisce che voglio accedere ad una altra rootdoc per qualche strana ragione non me lo fa fare.
      merd.
      che fo?
      Please consider the environment before printing this message, 50% of the above is useless!
<softv>

Pagina generata in 101 millisecondi

Utenti attivi: 6 nell'ultimo minuto, 24 negli ultimi cinque minuti, 52 negli ultimi 15 minuti