PDA

View Full Version : Nginx rules



Mike
April 29, 2010, 12:28 PM
I have this rewrite rules

# define paging
rewrite ^/([a-zA-Z0-9]+)?/index([0-9]*).ht(m?ml?)$ /index.php?page=$1&rlVareables=$2&pg=$3$query_string last;
# define listing
rewrite ^/([a-zA-Z0-9]+)?/(.*)-l([0-9]*).ht(m?ml?)$ /index.php?page=$1&rlVareables=$2&listing_id=$3$query_string last;
# define single pages
rewrite ^/([-a-zA-Z0-9]+)?.ht(m?ml?)$ /index.php?page=$1$query_string last;
# define other pages
rewrite ^/([a-zA-Z0-9]+)?/(.*)(.ht(m?ml?)|/+)$ /index.php?page=$1&rlVareables=$2$query_string last;


but add-listing links don't work
like this
http://mydomain/add-listing/books/books ... ories.html (http://mydomain/add-listing/books/books-accessories.html)
http://mydomain/post-ad/dvds-and-movies/dvd/

Mike
May 11, 2010, 11:54 AM
Hello Dmitri,

So as i understand url is not working if more than one subcategory?
Actually it is first time i hear this issue, maybe it is related changes you made.
You can PM me website url and ftp i will check this issue

geoclicks
May 11, 2012, 04:21 AM
Does anyone have a working rewrite configuration for Flynax version 4.x? There are more rules in the current version than the one previous:



# define system languages
RewriteRule ^([^//]+)/?(.{2})?/$ index.php?page=$1 [QSA,L]

# define paging
RewriteRule ^([^//]+)/?(.*)?/index([0-9]*).ht(m?ml?)$ index.php?page=$1&rlVareables=$2&pg=$3 [QSA,L]

# define listing
RewriteRule ^([^/][\w\-\_]+)(.+)-l?([0-9]+).ht(m|ml)$ index.php?page=$1&rlVareables=$2&listing_id=$3 [QSA,L]

# define account details request
RewriteRule ^((\w{2})/)?([\w-_]{3,})$ index.php?page=$3&lang=$2&account_request [QSA,L]

# define single pages
RewriteRule ^([^//]+)/?(^/*)?.ht(m?ml?)$ index.php?page=$1 [QSA,L]

# define other pages
RewriteRule ^([^//]+)/?(.*)?/?(.*)?(.ht(m?ml?)|/+)$ index.php?page=$1&rlVareables=$2 [QSA,L]

Any help would be appreciated.

Adam Farkas
March 14, 2013, 06:41 PM
I realize this thread is old, but does anyone have a complete set of rules for nginx with 4.x?

thanks!

Mike
April 11, 2013, 05:10 AM
In case somebody need nginx rules, here they are:




#---- flynax rewrite section start ---- #
#non last slash redirect
rewrite ^([^\.]*[^/])$ $1/ permanent;

#personal address subdomains rewrite
if ($host ~ ((?!www\.|m\.|mobile\.).*)\.(.*) ) {
set $subdomain $1;
}
if ( $subdomain ) {
rewrite ^(.*)$ /index.php?page=$subdomain&wildcard&rlVareables=$request_uri last;
}

if (!-e $request_filename)
{
#define paging
rewrite ^/([^/]*)/((.*)/)?(index([0-9]*).ht(m?ml?))?$ /index.php?page=$1&rlVareables=$3&pg=$5 last;

#define listing details
rewrite ^/([^/]*)/((.*)/)?(.+)-l?([0-9]+).ht(m|ml)$ /index.php?page=$1&rlVareables=$3&listing_id=$5 last;

#define browse
rewrite ^/([^/]*)/(.*)(\.html|\.htm|\/)$ /index.php?page=$1&rlVareables=$2 last;

#define single pages
rewrite ^/(.+)(\.html|\.htm|\/)$ /index.php?page=$1 last;

#sitemap rewrite rules
rewrite ^/([a-z_]*)?sitemap([0-9]*).xml$ /plugins/sitemap/sitemap.php?search=google&number=$2&mod=$1 last;
}
#---- flynax rewrite section end ---- #




In my case it was in the server section of the nginx config file

I also can confirm that flynax works on nginx +fastcgi php server without apache )

Mike
June 26, 2013, 03:47 AM
update:
for the sitemap plugin additional rule required



#sitemap rewrite rules
rewrite ^/([a-z_]*)?sitemap([0-9]*).xml$ /plugins/sitemap/sitemap.php?search=google&number=$2&mod=$1 last;

Mike
August 19, 2013, 10:43 AM
FYI:

We don't provide nginx server configuration service as any other web server configurations or tweaking service. You have to do it with your server administrator or hosting support.

Yes there are rewrite rules in the thread to use with nginx server, but only the rules - you have to copy them to the nginx configuration file. Please consider that the rest of configuration should be done on your side

Alex
September 26, 2013, 05:26 AM
Hi all,

If your Flynax script is installed in a subdirectory then use a location tag below:



location /your_subdomain/
{
root /full/path/from/root/your_subdomain/;

#non last slash redirect
rewrite ^([^\.]*[^/])$ $1/ permanent;

#personal address subdomains rewrite
if ($host ~ ((?!www\.|m\.|mobile\.).*)\.(.*) ) {
set $subdomain $1;
}
if ( $subdomain ) {
rewrite ^(.*)$ /index.php?page=$subdomain&wildcard&rlVareables=$request_uri last;
}

if (!-e $request_filename)
{
#define paging
rewrite ^/([^/]*)/((.*)/)?(index([0-9]*).ht(m?ml?))?$ /index.php?page=$1&rlVareables=$3&pg=$5 last;

#define listing details
rewrite ^/([^/]*)/((.*)/)?(.+)-l?([0-9]+).ht(m|ml)$ /index.php?page=$1&rlVareables=$3&listing_id=$5 last;

#define browse
rewrite ^/([^/]*)/(.*)(\.html|\.htm|\/)$ /index.php?page=$1&rlVareables=$2 last;

#define single pages
rewrite ^/(.+)(\.html|\.htm|\/)$ /index.php?page=$1 last;

#sitemap rewrite rules
rewrite ^/([a-z_]*)?sitemap([0-9]*).xml$ /plugins/sitemap/sitemap.php?search=google&number=$2&mod=$1 last;
}
}

Client_uk
June 16, 2015, 08:15 PM
Are there any instructions how to enable this for nginx+fastcgi?

my current settings are:


location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

but the website responds with the 404 code

Alex
June 17, 2015, 03:35 AM
Hello,

The rewrite rules not dependent on this nginx+fastcgi or nginx+apache
Show us the contents of your tag server {...} not just one location ~ \.php$ {...}

Client_uk
June 17, 2015, 05:31 AM
Server {} are default. But will post it once I have access to it

Client_uk
June 17, 2015, 08:12 AM
Here is my code



server {
listen 80;


root /var/www;
index index.php index.html index.htm;

server_name example.com;

location / {
try_files $uri $uri/ /index.html;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www;
}

# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

}

}

Client_uk
June 18, 2015, 05:34 PM
Is anything else needed to solve this issue?

Alex
July 22, 2015, 03:40 AM
server {
server_name www.flynax.dev flynax.dev;
access_log /var/www/flynax.dev/logs/access.log;
error_log /var/www/flynax.dev/logs/error.log;
root /var/www/flynax.dev/public_html;


# General Flynax rules


# define paging
rewrite ^/([^//]+)/?(.*)?/index([0-9]*).html$ /index.php?page=$1&rlVareables=$2&pg=$3 break;


# define listing
rewrite ^/([^/]+)(/?(.+))?-l?([0-9]+).html$ /index.php?page=$1&rlVareables=$3&listing_id=$4 break;


# TODO: wildcard request


# account request (sub-directory)
rewrite "^/((\w{2})/)?([\w-_]{3,})$" /index.php?page=$3&lang=$2&account_request break;


# define single pages
rewrite ^/([^//]+)/?(^/*)?.html$ /index.php?page=$1 break;


# define other pages
rewrite ^/([^//]+)/?(.*)?/?(.*)?(.html|/+)$ /index.php?page=$1&rlVareables=$2 break;


# Google and Yahoo sitemap
rewrite ^/([a-z_]*)?sitemap([0-9]*).xml$ /plugins/sitemap/sitemap.php?search=google&number=$2&mod=$1 break;
rewrite ^/yahoo-sitemap.txt$ /plugins/sitemap/sitemap.php?search=yahoo break;
rewrite ^/urllist.txt$ /plugins/sitemap/sitemap.php?search=urllist break;


# catch all
error_page 404 "Not Found";


location = /favicon.ico {
log_not_found off;
access_log off;
}


location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}


# Deny all attempts to access hidden files.
location ~ /\. {
deny all;
}


# Deny access to any files with a .php* extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php[0-9]*$ {
deny all;
}


# General Flynax rules END


location / {
index index.php;
}


location /admin/ {
index index.php;
}


# use fastcgi for all php files
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/flynax.dev/public_html$fastcgi_script_name;
}
}

Client_uk
September 9, 2015, 04:33 AM
perfect! but didnt check if this works with the sitemap yet

Leandro
September 22, 2016, 04:17 AM
Hello,

I'm migrating server, leaving the Apache for Nginx which is much faster than the last.

I have a big problem .... already migrated everything, including the database that has a lot of work, but is now ok.

The problem is that the rewrite mode and friendly url stopped working.

- How do I get back? code available at Alex, I put in the .htaccess file, but still does not work.
- At the site of administration, I must leave marked the Module option "Apache Rewrite" Settings> General? or not?
- Someone could make the friendly url running on Nginx without Apache?

Thank you.

Leandro.

Marius Carneala
February 15, 2017, 01:55 PM
Hi Alex,

Did you manage to sort out the wildcard request?

Thanks!

Locations Vn
October 14, 2017, 02:10 PM
Dear Alex

It is great script for version 4.5 but it doesn't work in 4.5.2 on front-end user.

It just works for back-end. Could you show me how to fix it?

Best

Brian Jester
November 2, 2017, 01:10 AM
Hello Alex,

I have tried this in Flynax 4.6 but I am getting a 404 error. :( Can someone confirm if any of these rules are working in v4.6? I would be very grateful for your time/effort. Maybe I am just overlooking something very basic?

FYI: The installation tells me undefined for mod_rewrite, is this supposed to change green and to enabled on that install screen, or is it not updated for nginx for that install screen? I would like to move on from this part as quickly as possible.

Please help...
Thank you!
Brian

Brian Jester
November 6, 2017, 09:14 PM
Kevin,

I tried replying to the support@flynax, in case you didn't get it, I would surely appreciate your time and effort to get me the nginx rules that will work with flynax as opposed to the apache web server!

Thanks a million!
Brian

Bahram Soltanirad
November 7, 2017, 05:45 AM
I don't know, if it helps people like to convert .htaccess from apache to nginx.
http://winginx.com/en/htaccess

Brian Jester
November 7, 2017, 10:50 PM
Hello Bahram,

I am looking for the new rules for nginx, I believe Kevin has them, I am just getting to check my emails at this time, but if I have to, I will resort to apache server until new NGINX rules have been up to date.

Thank you
Brian

Brian Jester
November 10, 2017, 03:31 AM
server {
server_name www.flynax.dev flynax.dev;
access_log /var/www/flynax.dev/logs/access.log;
error_log /var/www/flynax.dev/logs/error.log;
root /var/www/flynax.dev/public_html;


# General Flynax rules


# define paging
rewrite ^/([^//]+)/?(.*)?/index([0-9]*).html$ /index.php?page=$1&rlVareables=$2&pg=$3 break;


# define listing
rewrite ^/([^/]+)(/?(.+))?-l?([0-9]+).html$ /index.php?page=$1&rlVareables=$3&listing_id=$4 break;


# TODO: wildcard request


# account request (sub-directory)
rewrite "^/((\w{2})/)?([\w-_]{3,})$" /index.php?page=$3&lang=$2&account_request break;


# define single pages
rewrite ^/([^//]+)/?(^/*)?.html$ /index.php?page=$1 break;


# define other pages
rewrite ^/([^//]+)/?(.*)?/?(.*)?(.html|/+)$ /index.php?page=$1&rlVareables=$2 break;


# Google and Yahoo sitemap
rewrite ^/([a-z_]*)?sitemap([0-9]*).xml$ /plugins/sitemap/sitemap.php?search=google&number=$2&mod=$1 break;
rewrite ^/yahoo-sitemap.txt$ /plugins/sitemap/sitemap.php?search=yahoo break;
rewrite ^/urllist.txt$ /plugins/sitemap/sitemap.php?search=urllist break;


# catch all
error_page 404 "Not Found";


location = /favicon.ico {
log_not_found off;
access_log off;
}


location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}


# Deny all attempts to access hidden files.
location ~ /\. {
deny all;
}


# Deny access to any files with a .php* extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php[0-9]*$ {
deny all;
}


# General Flynax rules END


location / {
index index.php;
}


location /admin/ {
index index.php;
}


# use fastcgi for all php files
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/flynax.dev/public_html$fastcgi_script_name;
}
}


Mike,

I am going to send my nginx.conf file and default config file from the sites-available folder. I am sending you both as I have not modified the nginx.conf file, just the default file from the sites-available folder. It's my understanding that the server section and location section(s) that you have referred to in your last email is in the default file. I have enclosed both files in one zip file for you to check. I appreciate you help in advance!

Thank you Mike!
Brian

Brian Jester
November 11, 2017, 04:59 AM
server {
server_name www.flynax.dev flynax.dev;
access_log /var/www/flynax.dev/logs/access.log;
error_log /var/www/flynax.dev/logs/error.log;
root /var/www/flynax.dev/public_html;


# General Flynax rules


# define paging
rewrite ^/([^//]+)/?(.*)?/index([0-9]*).html$ /index.php?page=$1&rlVareables=$2&pg=$3 break;


# define listing
rewrite ^/([^/]+)(/?(.+))?-l?([0-9]+).html$ /index.php?page=$1&rlVareables=$3&listing_id=$4 break;


# TODO: wildcard request


# account request (sub-directory)
rewrite "^/((\w{2})/)?([\w-_]{3,})$" /index.php?page=$3&lang=$2&account_request break;


# define single pages
rewrite ^/([^//]+)/?(^/*)?.html$ /index.php?page=$1 break;


# define other pages
rewrite ^/([^//]+)/?(.*)?/?(.*)?(.html|/+)$ /index.php?page=$1&rlVareables=$2 break;


# Google and Yahoo sitemap
rewrite ^/([a-z_]*)?sitemap([0-9]*).xml$ /plugins/sitemap/sitemap.php?search=google&number=$2&mod=$1 break;
rewrite ^/yahoo-sitemap.txt$ /plugins/sitemap/sitemap.php?search=yahoo break;
rewrite ^/urllist.txt$ /plugins/sitemap/sitemap.php?search=urllist break;


# catch all
error_page 404 "Not Found";


location = /favicon.ico {
log_not_found off;
access_log off;
}


location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}


# Deny all attempts to access hidden files.
location ~ /\. {
deny all;
}


# Deny access to any files with a .php* extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php[0-9]*$ {
deny all;
}


# General Flynax rules END


location / {
index index.php;
}


location /admin/ {
index index.php;
}


# use fastcgi for all php files
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/flynax.dev/public_html$fastcgi_script_name;
}
}


I have copied/pasted the above code into my nginx.conf file, but when restarting the server I get an error: It's the journal error, having to do with nginx.conf, when I take that code out, the error is gone, but no mod_rewrite, can someone confirm that the code posted by alex does in fact work in v4.6?

If it works in 4.6 can you post your nginx.conf file so I can take a look?

Thank you
Brian

Brian Jester
March 24, 2018, 02:22 PM
Hello,

Has anyone have mod_rewrite working with nginx? I am using ubuntu 16.04 and the best that I have come to is getting rid of the 404 errors and replaced them with no error, but just a page refresh when clicking on a link, so no I have not yet made it work yet but am still looking for a solution. If anyone has it working I would be grateful for the share.

I have not touched the nginx.conf, rather I have modified the /etc/nginx/sites-available/default configuration file. Also, I have tried the other code, specifically by alex, but that has not worked either...I even tried to comment out the other location directives when add alexes' code, but still not working. :mad:

Is there any obvious mistakes in this file?

/etc/nginx/sites-available/default file:


##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name localhost;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}


location /flynax/ {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
index index.php index.html index.htm;
try_files $uri $uri/ /flynax/index.php?$args;
}



# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}

Brian

Pablo Esco
May 11, 2019, 12:07 AM
Add rule for hybridAuthLogin


location /plugins/hybridAuthLogin {



if (!-f $request_filename){
rewrite /(.*)/(.*) /plugins/hybridAuthLogin/requests.php?provider=$1&$2 last;
}


}