•  · 156 friends

UNA nginx rewrite rules

location / {
    index index.html index.htm index.php;

    rewrite "^/path-to-una/page/(.*)$" /path-to-una/page.php?i=$1 last;
    rewrite "^/path-to-una/m/(.*)$" /path-to-una/modules/index.php?r=$1 last;
    rewrite "^/path-to-una/s/([a-zA-Z0-9_]+)/([a-zA-Z0-9\.]+)" /path-to-una/storage.php?o=$1&f=$2 last;

    if (!-e $request_filename ) {
        rewrite  ^/path-to-una/(.+)$  /path-to-una/r.php?_q=$1  last;
        break;
    }
 }

 

 

0 0 0 0 0 0
  • 4738
Replies (56)
    • It is now running under php7.2 - long story.  Same issue.  The images and videos are uploaded  - just can't see them.  Hit refresh - and they appear.

      Here is a copy of the error log - the only activity it is reporting on is the upload of images to the timeline.  

      https:// www.manconnector.com /error.txt

      0 0 0 0 0 0
      • I see two problems in your logs:

        1) upstream sent too big header while reading response header from upstream

        you will probably need to increase some setting in Nginx configuration, try to set:

        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;

        in php handled block, usually it begins like this - location ~ \.(php|php5)$ {

        2) open_basedir restriction in effect

        please try to remove open_basedir restriction in php confoguration if possible

        in the future we'll try to make UNA work with this restruction set - https://github.com/unaio/una/issues/1881

        0 0 0 0 0 0
        • Thank you so much. That was extremely helpful.  The fastcgi settings worked.  Working on the basedir restrictions.

          0 0 0 0 0 0
          • rewrite "^/path-to-una/s/([a-zA-Z0-9_]+)/([a-zA-Z0-9\.]+)" /path-to-una/storage.php?o=$1&f=$2 last;


            This line is causing my NGinx server to hang on startup. A look at the init.d logs shows that the above line is causing a config error like this (not real server name): Mar 30 22:04:50 SUPERSPARC-SC001.contoso.corp nginx[4138]: nginx: [emerg] invalid variable name in /etc/nginx/nginx.conf:

            I am running Novell Netware 6 and NGinx 1.17 (Linux Kernel 4.3.2)

            0 0 0 0 0 0
            • rewrite "^/path-to-una/s/([a-zA-Z0-9_]+)/([a-zA-Z0-9\.]+)" /path-to-una/storage.php?o=$1&f=$2 last;


              This line is causing my NGinx server to hang on startup. A look at the init.d logs shows that the above line is causing a config error like this (not real server name): Mar 30 22:04:50 SUPERSPARC-SC001.contoso.corp nginx[4138]: nginx: [emerg] invalid variable name in /etc/nginx/nginx.conf:

              I am running Novell Netware 6 and NGinx 1.17 (Linux Kernel 4.3.2)

              It maybe you've inserted it in a wrong place, please try to paste in inside location clause.

              0 0 0 0 0 0
              • Here is my NGinx root server config block in it's entirety:

                location / {
                autoindex on;
                root /srv/www/htdocs/;
                index index.html index.htm index.php;
                }
                location ~ \.php$ {
                root /srv/www/htdocs/;
                try_files $uri $uri/ /index.php?$args;
                # try_files $uri $uri/ /elgg/index.php?$args;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME
                $document_root$fastcgi_script_name;
                fastcgi_param SCRIPT_NAME $fastcgi_script_name;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_index index.php;
                fastcgi_pass 127.0.0.1:9000;
                rewrite "^/page/(.*)$" /page.php?i=$1 last;
                rewrite "^/m/(.*)$" /modules/index.php?r=$1 last;
                "^/s/([a-zA-Z0-9_]+)/([a-zA-Z0-9\.]+)" /storage.php?o=$1&f=$;
                if (!-e $request_filename ) {
                rewrite ^/(.+)$ /r.php?_q=$1 last;
                break;
                }
                }

                The lines commented out are what i believe to be the offending rewrite rules. Please advise on what i should do. UNA is also giving vague SQL query errors and is not displaying form fields correctly. I have at this point disable UNA entirely, however I would reinstall it if I could be better advised on why these errors are occuring.

                0 0 0 0 0 0
                • There are many problems in your code, please move all UNA related rules to "location /" block. Also you need to remove "try_files" rules.

                  0 0 0 0 0 0
                  • Thanks for the advice. i believe i have to have the "try_files" rules because I am using php-fpm instead of FastCGI. However I will try moving the rewrite rules.

                    0 0 0 0 0 0
                    • Helllo Alex T⚜️ 

                      I think my problem posted in 

                      is related with nginx configuration. 

                      Could you help me to check.

                      Thanks in advance!

                      0 0 0 0 0 0
                      • Try to play with chmod/chown and look to error log

                        0 0 0 0 0 0
                        • Hi everyone. I'm trying to install una on my cloud host and the audit gave the green light on everything except the rewrite (which admittedly - I'm completely lost on). I don't know where I'm supposed to put the rewrite code and what of that code I'm supposed to change to my info. I have access through the SSH, but don't want to break anything since I don't know what I'm doing with that part... is there  somewhere that shows more documentation or guidance than just the rule?

                          0 0 0 0 0 0
                          • Hello Danielle !

                            If your site has the working links like UNA_url/page/discussions-home then no need to worry about this message of rewrite module, because it is often to hard the detect it with PHP tools.

                            0 0 0 0 0 0
                            • Hi - wondering if you can help -- have installed UNA on a AWS nginx server --all good -  have run the scrip and ran the rewrite rules -- my UNA application files are in the "opt/bitnami/nginx/html" folder and my code below to set the rewrite rules was added to replace the original "location" block in the "nginx.conf" file within the "opt/bitnami/nginx/conf" folder - the added code is as follow:

                              location / {
                              index index.html index.htm index.php;

                              rewrite "^/html/page/(.*)$" /html/page.php?i=$1 last;
                              rewrite "^/html/m/(.*)$" /html/modules/index.php?r=$1 last;
                              rewrite "^/html/s/([a-zA-Z0-9_]+)/([a-zA-Z0-9\.]+)" /html/storage.php?o=$1&f=$2 last;

                              if (!-e $request_filename ) {
                              rewrite ^/html/(.+)$ /html/r.php?_q=$1 last;
                              break;
                              }
                              }

                              All works fine when I point to //myserver/index.php - I see the homepage and can login to my "Studio" page as well -- but every time I try to do something else, it points me to a "/page/....." location - for example if I go to "Dashboard' then it points me to //myserver/page/dashboard and I get a "404 Not Found"

                              Is there anything I am missing - how can I make it so it loads all pages requested without the error? - is there anything wrong in the code?

                              Thank you

                              0 0 0 0 0 0
                              • Please try to remove "html/" from your rewrite rules.

                                0 0 0 0 0 0
                                • Thanks Alex it works!

                                  0 0 0 0 0 0
                                  • Just another quick question Alex  - all is working fine now and have been able to get some users on and posting away - I noticed that if I try to "customize" my Design Protean with new design it causes nginx error "502 bad gateway"  - this happens after changing the design to another Protean style which I have created (PS I have also clear the CSS cache as per instrutions) -- is there anything wrong in the settings that I need to adjust?  - thanks again

                                    0 0 0 0 0 0
                                    • Just another quick question Alex  - all is working fine now and have been able to get some users on and posting away - I noticed that if I try to "customize" my Design Protean with new design it causes nginx error "502 bad gateway"  - this happens after changing the design to another Protean style which I have created (PS I have also clear the CSS cache as per instrutions) -- is there anything wrong in the settings that I need to adjust?  - thanks again

                                      Please create separate thread for another problem, and also specify more info, such as php error log, and what you changed particularly.

                                      0 0 0 0 0 0
                                      • I am getting 504 Gateway Time-out when I am trying to go into the Studio for the first time.

                                        image_transcoder.php?o=bx_froala_image&h=4807&dpx=1&t=1614679822

                                        Please advise

                                        0 0 0 0 0 0
                                        • I remember the problem in lost space in rule code. Just read it careful you find it.

                                          0 0 0 0 0 0
                                          • Sorry:  I do not know where to look...

                                            0 0 0 0 0 0
                                            • Hello UnitekSystemsLtd !

                                              The first step with error 504 - check the load of the processor and memory. Maybe there is a lack of resources.

                                              0 0 0 0 0 0
                                              • UNA is a VM with 4 cores and 64GB Memory.  and 500GB SSD.  The Mysql {MariaDB} is on a separate VM with the same spec.  The CPUs are running at 0% in Hyper-V.  Should not be CPU or Memory

                                                I am running v12.0.0.0 - has anyone installed this version?

                                                0 0 0 0 0 0
                                                • 0 0 0 0 0 0
                                                  • I have been through that code and there is no difference to what you are showing...

                                                    0 0 0 0 0 0
                                                    • You loose this game) With Una you need to be more attentive and patience than other. 

                                                      0 0 0 0 0 0
                                                      • I already tried that;  I get the same issue...does not make a diference

                                                        0 0 0 0 0 0
                                                        • I am getting 504 Gateway Time-out when I am trying to go into the Studio for the first time. 

                                                          Any ideas?

                                                          0 0 0 0 0 0
                                                          • Add full config I try to look.

                                                            0 0 0 0 0 0
                                                            • I can only copy a screen shot; as this is a VM on a remote server:  I am using RDP and Hyper-V to get the terminal windows...

                                                              image_transcoder.php?o=bx_froala_image&h=4812&dpx=1&t=1614727948


                                                              Also trying this as I am trying to get the SSL to work:  my problem here is I installed it with http:// on the installation.  I need to find the MySql table to I can change this to https://..........  

                                                              image_transcoder.php?o=bx_froala_image&h=4814&dpx=1&t=1614728579

                                                              0 0 0 0 0 0
                                                              • header.inc.php edit in /inc/

                                                                0 0 0 0 0 0
                                                                • Thanks for that :)

                                                                  0 0 0 0 0 0
                                                                  • Clear files on cache folder. Clear browser cache and try to login studio. 

                                                                    0 0 0 0 0 0
                                                                    • I cleared my browser cache.  

                                                                      rm /var/www/xyz.com/html/cache/*.* has been executed

                                                                      I still have the same issue

                                                                      0 0 0 0 0 0
                                                                      • Yes

                                                                        0 0 0 0 0 0
                                                                        • I fixed the 504 Gateway Time-out by adding fastcgi_read_timeout 300

                                                                          But The Studio is very slow... Why!?


                                                                          image_transcoder.php?o=bx_froala_image&h=4820&dpx=1&t=1614797551

                                                                          I ran a Server Audit:  and get this FAIL

                                                                          image_transcoder.php?o=bx_froala_image&h=4821&dpx=1&t=1614800141

                                                                          0 0 0 0 0 0
                                                                          • If you look from rdp its normal to be slow! 

                                                                            0 0 0 0 0 0
                                                                            • I am on my laptop; not via RDP.  The performance is very slow in Studio only.   so I need too add another location to the nginx configuration for studio?

                                                                              0 0 0 0 0 0
                                                                              • check full audit clear cache idk Wharton be slow maybe you have old laptop) with bad cooling or another software

                                                                                0 0 0 0 0 0
                                                                                • And if you use it on shared hosting!

                                                                                  0 0 0 0 0 0
                                                                                  • nothing to do with the laptop...  this is a performance issue on the Debian server.  not the laptop I am using

                                                                                    0 0 0 0 0 0
                                                                                    • Than concentrate on server settings i think that's not una. 

                                                                                      0 0 0 0 0 0
                                                                                      • below is my current /etc/nginx/sites-available

                                                                                        Issues I am having - any ideas?:

                                                                                        • Performance in Studio:  this was fixed by adding 127.0.01 <domain name> in /etc/hosts/
                                                                                        • Images after uploaded are not displaying properly


                                                                                        image_transcoder.php?o=bx_froala_image&h=4829&dpx=1&t=1614918528

                                                                                        0 0 0 0 0 0
                                                                                        • the storage folder:  does that folder structure seem correct.  all the folders under bx_persons_pictures seem to go 3 folders deep.  and there is no images in any of the folders.  Any ideas?

                                                                                          image_transcoder.php?o=bx_froala_image&h=4832&dpx=1&t=1614931211

                                                                                          0 0 0 0 0 0
                                                                                          • Yes, it is. It was made to prevent the work of Linux limit on 32K of files in the 1 folder.

                                                                                            0 0 0 0 0 0
                                                                                            • Where do I put this rewrite code? What file do I change? I'm using cpanel.

                                                                                              I tried putting it in nginx.conf and it said that it rebuilt with errors

                                                                                              0 0 0 0 0 0
                                                                                              • Hello Genesis !

                                                                                                Usually, it is closed to edit the nginx.conf file via CPanel. You need to ask your hosting provider about it.

                                                                                                0 0 0 0 0 0
                                                                                                • A quick late add on this, if you are using plesk, from your site, go to your websites and then Hosting and DNS and then Apache & nginx Settings and put them in the Additional nginx directives

                                                                                                  0 0 0 0 0 0
                                                                                                  • Alex T⚜️ I am using plesk with apache proxy off. I got everything working, but when I open Apps market it will take forever to install an app and sometimes it will be done, I will see the fastcgi error in the log, wheel still going, and refresh and module will be there,. Also if I go into notifications I sometimes get 504 when it goes to load the settings. This lets me know I am still dealing with an issue. Here are my current NGINX directives: 

                                                                                                    location / {


                                                                                                        index index.html index.htm index.php;


                                                                                                        rewrite "^/page/(.*)$" /page.php?i=$1 last;


                                                                                                        rewrite "^/m/(.*)$" /modules/index.php?r=$1 last;


                                                                                                        rewrite "^/s/([a-zA-Z0-9_]+)/([a-zA-Z0-9\.]+)" /storage.php?o=$1&f=$2 last;


                                                                                                        if (!-e $request_filename ) {


                                                                                                            rewrite  ^/(.+)$  /r.php?_q=$1  last;


                                                                                                            break;


                                                                                                        }


                                                                                                    }

                                                                                                    # PROXY SETTINGS

                                                                                                    proxy_buffer_size          128k;

                                                                                                    proxy_buffers              4 256k;

                                                                                                    proxy_busy_buffers_size    256k;


                                                                                                    # FASTCGI

                                                                                                    fastcgi_buffers 16 16k;

                                                                                                    fastcgi_buffer_size 32k;


                                                                                                    sesion time

                                                                                                    proxy_connect_timeout 900;

                                                                                                    proxy_send_timeout 900;

                                                                                                    fastcgi_send_timeout 900;

                                                                                                    fastcgi_read_timeout 900;


                                                                                                    gzip off;


                                                                                                    brotli on;

                                                                                                    Is there anything I may be missing. You can see everything I have done in my plesk discussion here: https://una.io/page/view-discussion?id=8594 the error what I get with this is the fastcgi upstream error when it is installing apps from the studio. Or if anyone else has had experience with PLESK and NGINX that has ran into similar issues. 

                                                                                                    0 0 0 0 0 0
                                                                                                    • Kyle it maybe outgoing connections are restricted on your server, this maybe a reason, while you get connection timeout in Studio > Apps Market

                                                                                                      0 0 0 0 0 0
                                                                                                      • Alex T⚜️ It is after it is downloaded. They download fine and quick, it is when you are going to install them after. It will just spin past my 900S timeout it seems and when I refresh it will be there and show installed. The other area I get an issue is in profile notification settings. When going to load it, it takes forever and then 504 error. These are the only two areas thankfully I noticed an issue. I want to reinstall notifications again but afraid to, I do not want to mess anything up at this point. Got the site finally up to a workable state. I did add proxy_buffering on; to my directive just in case. Seen some fixes and that one was what I had but with the added line of it being on. I figured it would be on by default. Should I be safe to uninstall notifications and reinstall it? 

                                                                                                        0 0 0 0 0 0
                                                                                                        Not logged in users can't 'Comments Post'.
                                                                                                        10
                                                                                                        3
                                                                                                        1
                                                                                                        1
                                                                                                        1
                                                                                                        Added:
                                                                                                        Category:

                                                                                                        UNA - Network Infrastructure for Communities

                                                                                                        Close