Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Include example nginx configuration #37

Closed
doherty opened this issue May 8, 2012 · 2 comments
Closed

Include example nginx configuration #37

doherty opened this issue May 8, 2012 · 2 comments

Comments

@doherty
Copy link

doherty commented May 8, 2012

Here's my naive translation of the .htaccess RewriteRules you include. There might be a more nginx-y way of getting the same effect, but this appears to work.

server {
    listen *:80;
    server_name tweets.mikedoherty.ca;

    root /var/www/tweets.mikedoherty.ca/tweetnest;
    index index.php;

    access_log /var/log/nginx/tweets.mikedoherty.ca.access.log;
    error_log  /var/log/nginx/tweets.mikedoherty.ca.error.log;

    location /sort {
        rewrite ^/sort /sort.php last;
    }
    location /favourites {
        rewrite ^/favourites /favorites.php last;
    }
    location /favorites {
        rewrite ^/favorites /favorites.php last;
    }
    location /search {
        rewrite ^/search /search.php last;
    }
    if ($uri ~ ^/([0-9]+)/([0-9]+)/?$) {
        rewrite ^/([0-9]+)/([0-9]+)/?$ /month.php?y=$1&m=$2 last;
    }
    if ($uri ~ ^/([0-9]+)/([0-9]+)/([0-9]+)/?$) {
        rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)/?$ /day.php?y=$1&m=$2&d=$3 last;
    }
    location / {
        try_files $uri $uri/ /index.php;
    }
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_intercept_errors on;
        fastcgi_pass php-fcgi;
    }
    include w3ctc.conf;
}
@levifig
Copy link

levifig commented Oct 15, 2012

That's a bit messy! :)

Here's what I got running on http://nest.levifig.com

server {
  server_name  nest.levifig.com;
  root   /var/www/levifig.com/subdomains/nest;
  access_log /var/log/nginx/nest.levifig.access.log;

  include /etc/nginx/includes/serve_static;
  include /etc/nginx/includes/serve_php;

  rewrite ^/sort/?$ /./sort.php last;
  rewrite ^/favorites/?$ /./favorites.php last;
  rewrite ^/search/?$ /./search.php last;
  rewrite ^/([0-9]+)/([0-9]+)/?$ /./month.php?y=$1&m=$2;  rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)/?$ /./day.php?y=$1&m=$2&d=$3;
}

That's it! :)
I included 2 config files. Here they are:

include/serve_static (not required at all)

# Serve static files... FAST!!!!
location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm)$ {
  expires 30d;
  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;
}

include/serve_php (standard - required)

# Send PHP request to our PHP-FPM
location ~ \.php$ {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  fastcgi_intercept_errors on;
  # Change this to the host:port where your PHP-FPM is listening
  # By the way, this is the default
  fastcgi_pass localhost:9000;
  fastcgi_index index.php;
  fastcgi_connect_timeout 60;
  fastcgi_send_timeout 180;
  fastcgi_read_timeout 180;  fastcgi_buffer_size 128k;  fastcgi_buffers 4 256k;
  fastcgi_busy_buffers_size 256k;
  fastcgi_temp_file_write_size 256k;
}

I separate the PHP includes because that way I can just add that one line to any server to add PHP support across any of my config files! :)

Hope this helps!

@graulund
Copy link
Owner

graulund commented Jul 2, 2013

I'm not going to include this in the repository because even though I like nginx very much, not everybody uses it, and I want to keep the repository slim. However, @levifig, if you can clean your submitted config file (removing the parts with your username and local directory structure, etc.) and post it somewhere on the interwebs, I will happily link that from the Tweet Nest site. Thanks, guys! :)

@graulund graulund closed this as completed Jul 2, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants