Jump to content
  • 0

Nginx Rewrite


ServZoo

Question

Starting a new topic because the closest to this one is 8 months old.

 

Has anyone been successful in setting up SEF URL's with NGINX? I have read all the threads and the github project, but have been unsuccessful in getting the friendly URL's to work. 

 

I may be losing my mind, but it almost appears that the actual URLS work, but they aren't being displayed as links. For instance, if I click on anything, it adds index.php to the URL, but if I manually type /clients/login, it goes there without adding index.php to the URL.

 

Is there a setting somewhere that I'm missing that will fix the internal linking to SEF?

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

I have removed my directories and you will notice a lot of commented sections. I have been toying with making this work. I'm by no means an NGINX expert, but I normally don't have this many issues. I did try to run the config listed on github, but had way too many errors, so I modified until it started working.

 

Thanks for helping out!

# NGINX CONFIGURATION
server {
        listen 80;
        listen 443 ssl;
        server_name billing.servzoo.com;
        access_log   *removed*.access.log rt_cache;
        error_log    *removed*.error.log;

        #rewrite ^ https://$server_name$request_uri? permanent;
# This will redirect index.php index.htm to /
# Feel free to add other extension you need
#if ( $request_uri ~ "/index.(php|html?)" ) {
#       rewrite ^ /$1 permanent;
#}

        root *removed*/htdocs;
        index index.php index.htm index.html;

        server_name billing.servzoo.com;
        ssl_certificate *removed*.crt;
        ssl_certificate_key *removed*.key;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                try_files $uri =404;
                include fastcgi_params;
                fastcgi_pass php;
        }

# Disallow access to any file with .pdt extension
location ~ (\.pdt) {
    return 403;
}

# Ported from Blesta's .htaccess
# There are more than one way to accomplish this.
# You can use try_files rather than using IF ... rewrite;
#location / {
#  error_page     404 = @blesta; #IF file doesn't exist
#  log_not_found  off;
# For access to install file
#if ($request_uri ~ "^(.*)/install.php$"){
#    rewrite install.php /%1/install/ redirect;
#  }
#if (!-e $request_filename){
#rewrite ^(.*)$ /index.php;
#}
#}

#Core rewrite
location @blesta {
  rewrite ^(.*)$ /index.php last;
}
        include common/locations.conf;

}
Link to comment
Share on other sites

  • 0

Here is my \.php section  and basic rewrite section.  These are working for me.  I would post my entire config but it is huge right now as I have a lot of other directives for other things as well.  If this doesn't help I can look a bit more after lunch and make a basic nginx config.

    location ~ \.php$ {
        try_files $uri =404;
        # Tweak for Nginx to work with PHP from vendors
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 180;
        fastcgi_read_timeout 180;
        # Buffer settings increase to compensate for increased time/size due to SSL
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k; #
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_intercept_errors on;
        fastcgi_pass php;
        fastcgi_index index.php;
        include fastcgi_params;
    }
    location / {
        error_page     404 = @blesta; #IF file doesn't exist
        log_not_found  off;
    }

    #Core rewrite
    location @blesta {
        rewrite ^(.*)$ /index.php last;
    }
Link to comment
Share on other sites

  • 0

This is my full nginx conf on my dev install

server {
        listen 80;
        server_name DOMAIN;

        access_log PATH;
        error_log PATH;

        root PATH;

        index index.php;

        # serve static files directly
        location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
               access_log off;
               expires max;
        }

        # enforce NO www
        if ($host ~* ^www\.(.*))
        {
                set $host_without_www $1;
                rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
        }

        # catch all
        error_page 404 /index.php;

        location ~ \.php$ {
                fastcgi_index   index.php;
                fastcgi_pass    php;
                include         fastcgi_params;
                fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
                fastcgi_param   SCRIPT_NAME         $fastcgi_script_name;
        }

        location / {
                server_tokens off;
                client_max_body_size 20m;
                client_body_buffer_size 128k;
                try_files $uri $uri/ /index.php?$args;
        }

}

My fastcgi_params had a small change as well

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  HOSTNAME           $hostname;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
#fastcgi_param  SERVER_NAME        $server_name;
fastcgi_param  SERVER_NAME        $host;

I don't see any other changes I may have made.

Link to comment
Share on other sites

  • 0

Thanks again! I literally replaced my nginx conf (changing the paths), made the edits to fastcgi, cleared cache, restarted nginx and fpm. Everything loads up (still no change with the URLs.) They will load with SEF if I type it in, but all the links take you right back to index.php.

 

I'm stumped on this one! :-)

 

I appreciate the help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...