Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Howto run configure it right on Nginx Web Server ?

+6 votes
3,549 views
asked Oct 31, 2010 in Q2A Core by anonymous
Same as subject.

4 Answers

+1 vote
answered Nov 1, 2010 by gidgreen
If you can get nginx up and running with PHP and MySQL, it shouldn't be an issue.

Try this Google search for starters: http://www.google.com/search?q=nginx+php+mysql
+3 votes
answered Oct 27, 2011 by BubkaGob
edited Jun 11, 2016 by Scott

it works for default URLs like

/index.php?qa=123&qa_1=why-do-birds-sing

For SEO optimized urls like this /123/why-do-birds-sing you need to set rewrite rule in nginx config

if (!-e $fastcgi_script_name) {
    rewrite ^/(.+)?$ /index.php?qa-rewrite=$1 last;
}

or if your question2answer root directory is q2a

rewrite ^/q2a/(.+)?$ /q2a/index.php?qa-rewrite=$1 last;

it works fine for me

commented Dec 12, 2011 by Sergey Ivanov
try_files $uri $uri/ /index.php?qa-rewrite=$uri&$args;
commented Sep 3, 2013 by susuario
This answer went perfect in my server.

Thanks.
–1 vote
answered Apr 8, 2013 by Ashish Sharma
edited Jun 11, 2016 by Scott

For SEO optimized url & if root directory is different, below is the correct script

if (!-e $fastcgi_script_name) {
    rewrite ^/q2a/([a-z\/]+)(\?.+)?$ /q2a/index.php?qa-rewrite=$1&$args last;
}
commented Oct 13, 2013 by ac
This would not work at present where the q&a take the URL form /q2a/12/some-question as the number after q2a is not captured by your regex.

Also categories with symbols in URL will not work with this regex. For example Computers & IT category will become computers-%26-it in SEO friendly URL which will return a 404 for this regex you have given.

The regex in the answer above you by BubkaBob will work fine and is correct.
commented Feb 23 by moha16
not work this        

and this work

 location /qa {
                index index.php index.html index.htm;
                 if (!-e $fastcgi_script_name) {
                rewrite ^/qa/(.+)?$ /qa/index.php?qa-rewrite=$1 last;
         }

}

-------------------------------------------------------------------------------------------------------------------------------
nginx -t
 service nginx restart
+3 votes
answered Jan 6 by rrrhys

The other answers lead to 404's on all images etc for me. The one that worked for me was:

http://www.question2answer.org/qa/43081/the-correct-rule-of-rewrite-for-nginx

location / {
    index index.php index.html index.htm;
    if (!-e $request_filename) {
       rewrite ^/(.+)?$ /index.php?qa-rewrite=$1 last;
    }
}

commented Jul 4 by David Okwii
This worked for me after a long period of try and error
...