nginx rewrites nor working in some cases.

bubbl3

Active member
I actually have this in my nginx configuration and works great:
Code:
        location / {
             try_files $uri $uri/ /index.php?$uri&$args;
        }

But now i installed the smilies manager and it's url doesn't work, the call is:
Code:
/smilies/?editor_id=ctrl_message
And should rewrite to this:
Code:
index.php?smilies/&editor_id=ctrl_message
But it doesn't work :(

Anyone can suggest a rule to fix this?

Thanks in advance.
 
I have the addon installed and I don't have specific rule for that, it works fine.

Can you show more of your nginx file ?
 
I have the addon installed and I don't have specific rule for that, it works fine.

Can you show more of your nginx file ?
Sure:
Code:
server {
listen xxx.xxx.xxx.xxx:80;
 server_name mysite.com;
   rewrite ^(.*) https://www.mysite.com$1 permanent;
}
 
server {
listen xxx.xxx.xxx.xxx:80;
 server_name www.mysite.com;
 rewrite ^(.*) https://www.mysite.com$1 permanent;
}
 
server {
        listen xxx.xxx.xxx.xxx:443 ssl;
        ssl  on;
        ssl_certificate /var/www/clients/client1/web1/ssl/mysite.crt.pem;
        ssl_certificate_key /var/www/clients/client1/web1/ssl/mysite.key.pem;
        
        server_name mysite.com;
   
rewrite ^(.*) https://www.mysite.com$1 permanent;
}
 
server {
        listen xxx.xxx.xxx.xxx:443 ssl;
 
ssl  on;
        ssl_certificate /var/www/clients/client1/web1/ssl/mysite.crt.pem;
        ssl_certificate_key /var/www/clients/client1/web1/ssl/mysite.key.pem;
        
        server_name www.mysite.com;
 
        root   /var/www/mysite.com/web;
 
 
        index index.html index.htm index.php index.cgi index.pl index.xhtml;
 
 
        location ~ \.shtml$ {
            ssi on;
        }
 
 
        error_page 400 /error/400.html;
        error_page 401 /error/401.html;
        error_page 403 /error/403.html;
        error_page 404 /error/404.html;
        error_page 405 /error/405.html;
        error_page 500 /error/500.html;
        error_page 502 /error/502.html;
        error_page 503 /error/503.html;
        recursive_error_pages on;
        location = /error/400.html {
            internal;
        }
        location = /error/401.html {
            internal;
        }
        location = /error/403.html {
            internal;
        }
        location = /error/404.html {
            internal;
        }
        location = /error/405.html {
            internal;
        }
        location = /error/500.html {
            internal;
        }
        location = /error/502.html {
            internal;
        }
        location = /error/503.html {
            internal;
        }
 
        error_log /var/log/ispconfig/httpd/mysite.com/error.log;
        access_log /var/log/ispconfig/httpd/mysite.com/access.log combined;
 
        ## Disable .htaccess and other hidden files
        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
        }
 
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
 
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
 
        location /stats {
            index index.html index.php;
            auth_basic "Members Only";
            auth_basic_user_file /var/www/clients/client1/web1/.htpasswd_stats;
        }
 
        location ^~ /awstats-icon {
            alias /usr/share/awstats/icon;
        }
 
        location ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9010;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_intercept_errors on;
        }
 
        location /cgi-bin/ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            root /var/www/clients/client1/web1;
            gzip off;
            fastcgi_pass  unix:/var/run/fcgiwrap.socket;
            fastcgi_index index.cgi;
            fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
        }
 
        location / {
             try_files $uri $uri/ /index.php?$uri&$args;
     index index.php index.html;
        }
        
        location ~ /(internal_data|library) {
             internal;
        }
 
}
 
I've tried tro reproduce the problem, but without success. Maybe it's related to ssl, since I don't have that.

Well, try to add this rule, then :
Code:
location ~ ^/smilies/
{
    #rewrite ^/smilies/\?(.+)$ /index.php?smilies/&$1&$args last;
    try_files /index.php?smilies/&$args index.php;  // better
}
 
I've tried tro reproduce the problem, but without success. Maybe it's related to ssl, since I don't have that.

Well, try to add this rule, then :
Code:
location ~ ^/smilies/?
{
    rewrite ^/smilies/\?(.+)$ /index.php?smilies/&$1&$args last;
}

I'm so sorry I made you waste your time, i found the problem being i have a phisycal folder called smilies, that is the problem, will work around that, thanks much for your help.
 
By the way, the 2 first server {} , you can write something like :

Code:
server
{
    listen          xxx.xxx.xxx.xxx:80;
    server_name    www.mysite.com mysite.com;
    return 301      https://www.mysite.com$request_uri;
}

As says the documentation, better to use return 301. You can do the same for the other block.
 
Why do you use deprecated SSL config rules? Did you checked the Nginx documentation?
Also, why do you use double regex calls, when you can do everything in one single line?
Code:
server {
	listen		192.168.1.8:80;
	server_name	mysite.com *.mysite.com;
	rewrite ^	https://www.mysite.com$request_uri? permanent;
}
About 90% of your configuration is deprecated and your PHP is insecure, I could hack your site very easy.
Start with this basic configuration and READ the Nginx documentation, stop doing copy/paste from Internet. Most of those tutorials are just wrong, the ONLY proper place to learn how to configure your web server is on nginx.org/en/docs/.
 
Why do you use deprecated SSL config rules? Did you checked the Nginx documentation?
Also, why do you use double regex calls, when you can do everything in one single line?
Code:
server {
listen 192.168.1.8:80;
server_name mysite.com *.mysite.com;
rewrite ^ https://www.mysite.com$request_uri? permanent;
}
About 90% of your configuration is deprecated and your PHP is insecure, I could hack your site very easy.
I am still learning nginx, thanks to point it out, I'll check on it. Still i can't see where my php is insecure and how can you say it from the nginx configuration, there is a whole lot more job done in php5-fpm for that, but as i said, i'm an nginx novice.
 
As says the documentation, better to use return 301. You can do the same for the other block.
Rewrite permanent is the proper way, it automatically returns a 301 also. Not to mention that "return 301 URL" will not redirect all your links.
 
I can't see where my php is insecure and how can you say it from the nginx configuration.
Read on fastcgi_split_path_info variable, then you will understand how open you are. Change that ASAP in your config and for the love of God, please use php-fpm. :)
 
Rewrite permanent is the proper way, it automatically returns a 301 also. Not to mention that "return 301 URL" will not redirect all your links.

I know it's also a proper way, but can explain more what it won't redirect all my links ? Not sure to understand. Thanks.
 
Back
Top Bottom