We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Nginx Configuration Example [Answered] | Forum

Jody
Jody Apr 5 '13
All, I had a vanilla installation up and running on Apache and am trying to use nginx in front of it to serve the static content.  Can someone post an example site configuration file so that I can figure out how I screwed up the htaccess rewrites?

Thanks,

Jody
The Forum post is edited by ross Nov 19 '13
Jody
Jody Apr 9 '13
This should get you most of the way there if anyone is interested.  You may need to change the port depending on your setup.

server {
        root /var/www;
        listen 8080;
        server_name example.com www.example.com;
        access_log /var/log/nginx/epic.access.log;
        index index.html index.htm index.php;

        # define cache options
        expires 4000s;
        add_header Pragma public;
        add_header Cache-Control "max-age=4000, public, must-revalidate, proxy-revalidate";

        ## Disable viewing hidden files
        location ~ /\. {deny all; access_log off; log_not_found off;}
        location = /favicon.ico {access_log off; log_not_found off;}
        location = /robots.txt {allow all; access_log off; log_not_found off;}
        error_page 404 /404.html;
        location /404.html {internal;}
        location ~ \..*/.*\.php$ {return 403;}
        location ~* \.(txt|log)$ {
                allow 192.168.0.0/16;
                deny all;
        }

     location / {
        #       location / { rewrite (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$ /index.php; }
                #try_files $uri $uri/   /index.php?q=$uri&$args;
                try_files $uri $uri/ @rewrite1;
        }

        location @rewrite1 {
                rewrite (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$ /index.php;
        }
   
    ## Parse all .php file in the /var/www directory
        location ~ \.php {
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                #fastcgi_pass backend;
                fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
                include fastcgi_params;
                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_intercept_errors on;
                fastcgi_ignore_client_abort off;
                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;
        }

        location ~ (\.|ow_version.xml|INSTALL.txt|README.txt|UPDATE.txt) {
                return 404;
        }
The Forum post is edited by Jody Apr 9 '13
fbkca
fbkca Nov 1 '13
I've tried this but it seems that very few of the images are loading, styles aren't  loading... Javascript...


Does anyone have this running successfully on nginx???

The Forum post is edited by fbkca Nov 1 '13
fbkca
fbkca Nov 4 '13
No thoughts on this one? 


Oxwall, you recommend using Nginx in your oxwall wiki... you should also provide the configuration needed for it.


http://docs.oxwall.org/userguide:performance:optimization


Kinda pointless really... It's not up to our hosters to figure out the specific config for nginx. In my case, I have a dedicated machine, and while I have no problems installing and getting nginx running. It requires specific configuration for Oxwall to work.



The Forum post is edited by fbkca Nov 4 '13
fbkca
fbkca Nov 6 '13
Anyone...
fbkca
fbkca Nov 9 '13
Bump...
ben
ben Nov 10 '13
Jody installing nginx as reverse proxy if you need easy setup reverse proxy nginx you can install nginx admin. and it's just work without editing anything.


fbkca
fbkca Nov 11 '13
I'd prefer to run it as a pure nginx to get the most of out of switching.
ross Team
ross Nov 19 '13
FBKCA, what is your domain, please? 

There's no specific configuration needed, you just need to indicate correct domains and paths to the folders with the static in nginx config files. Mostly common settings will do. 

fbkca
fbkca Nov 19 '13
You know my domain, but my nginx access is only available on an unpublished IP for testing. So I have to manually edit my local hosts file to access it...


So is the config mentioned here too much and un-necessary? Nothing I try seems to work properly...


The onyl differenece is I'm not using php-fpm byt using fastcgi which I setup and adjusted the config for:


                fastcgi_pass 127.0.0.1:9000;



The Forum post is edited by fbkca Nov 19 '13
fbkca
fbkca Nov 19 '13
Ok, so form another thread by Kevin, I've finally got a config that works (still testing but looks good)


(replacing 24.5.6.7 with your server's IP):



***** START CONFIG *****

server {

        root /var/www/mysite;

        listen 24.5.6.7:80;

        server_name www.mysite.com;

        access_log /var/log/nginx/mysite.org.access.log;


if ($uri !~ "^/index.php"){set $rule_0 1$rule_0; }

if ($uri !~ "/ow_updates/index.php"){set $rule_0 2$rule_0; }

if ($uri !~ "/ow_updates/"){set $rule_0 3$rule_0; }

if ($uri !~ "/ow_cron/run.php"){set $rule_0 4$rule_0; }

if ($uri ~ "(/|.php|.html|.htm|.xml|.feed|robots.txt|.raw|/[^.]*)$"){set $rule_0 5$rule_0;}if ($rule_0 = "54321"){rewrite /(.*) /index.php; }


        location ~ \.php {

                fastcgi_split_path_info ^(.+\.php)(.*)$;

                #fastcgi_pass backend;

                fastcgi_pass 127.0.0.1:9000;

                fastcgi_index index.php;

                fastcgi_param SCRIPT_FILENAME /var/www/mysite$fastcgi_script_name;

                include fastcgi_params;

                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_intercept_errors on;

                fastcgi_ignore_client_abort off;

                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;

        }


}


***** END CONFIG *****