Discover Centmin Mod today
Register Now

Magento URL Rewrite issues

Discussion in 'Ecommerce / Shopping cart usage' started by Afaq, Dec 15, 2015.

Tags:
  1. Afaq

    Afaq Member

    61
    1
    8
    Aug 5, 2015
    Ratings:
    +2
    Local Time:
    10:34 AM
    hi, im currently in the process of moving my magento store from apache based server to nginx LEMP stack (Cent OS 7 with Centmin mod + Nginx 1.9.3 + MariaDB 10.0.21), and while the move has been ok, im having a lot of problems solving the url rewrites issues in nginx vhost conf file of my domain. Here is my current conf. file details

    Code:
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    #server {
    #            listen   80;
    #            listen   443 ssl;
    #            server_name www.domain.net;
    #            return 301 $scheme://www.domain.net$request_uri;
    #       }
    
    server {
      listen 80;
      server_name domain.net;
    
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/domain.net/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/domain.net/log/error.log;
    
      root /home/nginx/domains/domain.net/public;
    
      # prevent access to ./directories and files
      location ~ (?:^|/)\. {
       deny all;
      } 
    
      location / {
    
    # block common exploits, sql injections etc
    #include /usr/local/nginx/conf/block.conf;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      # Enable for vBulletin usage WITHOUT vbSEO installed
      # More example Nginx vhost configurations at
      # http://centminmod.com/nginx_configure.html
      try_files        $uri $uri/ @handler;
      index index.php;
      expires 30d;
    
      }
    
      location @handler {
      rewrite / /index.php;
      }
    
    location ~ .php/ {
       rewrite ^(.*.php)/ $1 last;
    }
    
    location ~ .php$ {
    #if(!-e $request_filename) {
    #  rewrite / /index.php last;
    #}
    
    expires  off;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param HTTPS $fastcgi_https;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param MAGE_RUN_CODE default;
    fastcgi_param MAGE_RUN_TYPE store;
    include fastcgi_params;
    
    # location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    # expires 1d;
    # log_not_found off;
    }
    
    }
    
    # include /usr/local/nginx/conf/staticfiles.conf;
    # include /usr/local/nginx/conf/php.conf;
    # include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
    # include /usr/local/nginx/conf/vts_server.conf;
    
    Following is my nginx conf. details

    Code:
    user              nginx nginx;
    worker_processes 3;
    worker_priority -10;
    
    worker_rlimit_nofile 260000;
    timer_resolution 100ms;
    
    pcre_jit on;
    
    pid         logs/nginx.pid;
    
    events {
        worker_connections  4096;
        accept_mutex on;
        accept_mutex_delay 200ms;
        use epoll;
        #multi_accept on;
    }
    
    http {
    limit_req_zone $binary_remote_addr zone=xwplogin:16m rate=40r/m;
    #limit_conn_zone $binary_remote_addr zone=xwpconlimit:16m;
    
    more_set_headers "Server: nginx centminmod";
    
    include /usr/local/nginx/conf/vts_http.conf;
    include /usr/local/nginx/conf/geoip.conf;
    include /usr/local/nginx/conf/pagespeedadmin.conf;
    include /usr/local/nginx/conf/fastcgi_param_https_map.conf;
    
    log_format      main    '$remote_addr - $remote_user [$time_local] $request '
                    '"$status" $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"'
                    ' "$connection" "$connection_requests" "$request_time"';
    
    map $scheme $fastcgi_https {
    default off;
    https on;
    }
    
    access_log  logs/access.log combined buffer=128k flush=5m;
    error_log   logs/error.log warn;
    
        index  index.php index.html index.htm;
        include       mime.types;
        default_type  application/octet-stream;
        charset utf-8;
    
            sendfile on;
            sendfile_max_chunk 512k;
            tcp_nopush  on;
            tcp_nodelay on;
            server_tokens off;
            server_name_in_redirect off;
          
            keepalive_timeout  8;
            keepalive_requests 1000;
            lingering_time 20s;
            lingering_timeout 5s;
            keepalive_disable msie6;
    
        gzip on;
        gzip_vary   on;
        gzip_disable "MSIE [1-6]\.";
            gzip_static on;
            gzip_min_length   1400;
            gzip_buffers      32 8k;
            gzip_http_version 1.0;
            gzip_comp_level 5;
            gzip_proxied    any;
            gzip_types text/plain text/css text/xml application/javascript application/x-javascript application/xml application/xml+rss application/ecmascript application/json image/svg+xml;
    
    client_body_buffer_size 256k;
    client_body_in_file_only off;
    client_body_timeout 10s;
    client_header_buffer_size 64k;
    ## how long a connection has to complete sending
    ## it's headers for request to be processed
    client_header_timeout  8s;
    client_max_body_size 50m;
    connection_pool_size  512;
    directio  4m;
    ignore_invalid_headers on;     
    large_client_header_buffers 8 64k;
    output_buffers   8 256k;
    postpone_output  1460;
    proxy_temp_path  /tmp/nginx_proxy/;
    request_pool_size  32k;
    reset_timedout_connection on;
    send_timeout     15s;
    types_hash_max_size 2048;
    server_names_hash_bucket_size 64;
    
    # for nginx proxy backends to prevent redirects to backend port
    # port_in_redirect off;
    
    open_file_cache max=50000 inactive=60s;
    open_file_cache_valid 120s;
    open_file_cache_min_uses 2;
    open_file_cache_errors off;
    open_log_file_cache max=10000 inactive=30s min_uses=2;
    
    ## limit number of concurrency connections per ip to 16
    ## add to your server {} section the next line
    ## limit_conn limit_per_ip 16;
    ## uncomment below line allows 500K sessions
    # limit_conn_log_level error;
    #######################################
    # use limit_zone for Nginx <v1.1.7 and lower
    # limit_zone $binary_remote_addr zone=limit_per_ip:16m;
    #######################################
    # use limit_conn_zone for Nginx >v1.1.8 and higher
    # limit_conn_zone $binary_remote_addr zone=limit_per_ip:16m;
    #######################################
    
    include /usr/local/nginx/conf/conf.d/*.conf;
    }
    
    The problem is all magento url's are ending with index.php which is throwing a 404 error of nginx. Ive searched and searched on various forums for a fix and tried almost anything that i could find to fix this issue but have been unsuccessful as yet. If i turn off the Web Server Rewrites in Magento then all url's work fine but that hurts SEO and i want it to be enabled.

    Here are some of the error logs from my domain and nginx.

    Domain error log
    Code:
    /home/nginx/domains/domain.net/public/hp-2311gt-23-3d-lcd-monitor-with-2-free-3d-glasses/[B]index.php[/B]" is not found (2: No such file or directory), client: 66.249.78.24, server: domain.net, request: "GET /hp-2311gt-23-3d-lcd-monitor-with-2-free-3d-glasses/ HTTP/1.1", host: "www.domain.net"
    
    Nginx error log

    Code:
    2015/12/15 10:08:14 [error] 6809#6809: OCSP_basic_verify() failed (SSL: error:27069065:OCSP routines:OCSP_basic_verify:certificate verify error:Verify error:unable to get local issuer certificate) while requesting certificate status, responder: ocsp.godaddy.com
    2015/12/15 10:09:07 [info] 7325#7325: [ngx_pagespeed 1.9.32.6-7321] No threading detected. Own threads: 1 Rewrite, 1 Expensive Rewrite.
    
    Thank you and hope someone comes up with a solution to this issue.
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,911
    6,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,404
    Local Time:
    3:34 PM
    Nginx 1.13.x
    MariaDB 5.5
    Centmin Mod is provide as is, so short of scripted related bugs or issues, any further optimisation to the web stack components - nginx, php-fpm, mariadb mysql, csf firewall etc or web app specific configurations are left to the Centmin Mod user to deal with. So I do not provide any free support for such.

    However, Centmin Mod users are free to help each other out and ask questions or give answers on this community forum. My hopes are that this community forum evolves so that more veteran long time Centmin Mod users help new Centmin Mod users out :)

    For Magento I have no experience, so please search this forum and ecommerce subforum at Ecommerce / Shopping cart usage | Centmin Mod Community for clues. You configuration is definitely incorrect. So check out Configuration Centmin Mod with magento | Centmin Mod Community first for clues

    i.e. duplication of php location matches as Centmin Mod already has one included in php.conf Configuration Centmin Mod with magento | Page 2 | Centmin Mod Community edit: ok i see you commented out php.conf includes so not using Centmin Mod's version
     
  3. eva2000

    eva2000 Administrator Staff Member

    30,911
    6,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,404
    Local Time:
    3:34 PM
    Nginx 1.13.x
    MariaDB 5.5
  4. eva2000

    eva2000 Administrator Staff Member

    30,911
    6,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,404
    Local Time:
    3:34 PM
    Nginx 1.13.x
    MariaDB 5.5
    also could be related to your use of own .php location context
    Code:
    location ~ .php$ {
    #if(!-e $request_filename) {
    #  rewrite / /index.php last;
    #}
    
    expires  off;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param HTTPS $fastcgi_https;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param MAGE_RUN_CODE default;
    fastcgi_param MAGE_RUN_TYPE store;
    include fastcgi_params;
    
    # location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    # expires 1d;
    # log_not_found off;
    }
    
    }
    instead maybe copy /usr/local/nginx/conf/php.conf to a new file /usr/local/nginx/conf/php-magento.conf
    Code:
    cp -a /usr/local/nginx/conf/php.conf /usr/local/nginx/conf/php-magento.conf
    then edit /usr/local/nginx/conf/php-magento.conf and only append and replace those specific additional magento changes to php-magento.conf and include that instead in your nginx vhost

    Code:
    #include /usr/local/nginx/conf/php.conf;
    /usr/local/nginx/conf/php-magento.conf
    seems there's only 2 specific settings to add to php-magento.conf
    Code:
    fastcgi_param MAGE_RUN_CODE default;
    fastcgi_param MAGE_RUN_TYPE store;
     
  5. eva2000

    eva2000 Administrator Staff Member

    30,911
    6,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,404
    Local Time:
    3:34 PM
    Nginx 1.13.x
    MariaDB 5.5
  6. Afaq

    Afaq Member

    61
    1
    8
    Aug 5, 2015
    Ratings:
    +2
    Local Time:
    10:34 AM
    thank you for the quick reply. will do these changes and report back whether they work or not