Alias in Nginx Config
Igor Sysoev
is at rambler-co.ru
Wed Jul 29 12:50:47 MSD 2009
On Tue, Jul 28, 2009 at 04:47:26PM -0400, APseudoUtopia wrote:
> 2009/7/26 Igor Sysoev <is at rambler-co.ru>:
> > On Sun, Jul 26, 2009 at 02:07:28PM -0400, APseudoUtopia wrote:
> >
> >> Hey list,
> >>
> >> How does one create an alias in nginx? Here's my setup:
> >>
> >> My web-root is /usr/local/www/main. It's a copy of a SVN repo, so I
> >> cannot manually add any folders in there.
> >> I want to make an alias from domain.com/wiki to /usr/local/www/wiki.
> >> I've tried the following code:
> >>
> >> location = /wiki {
> >> alias /usr/local/www/wiki;
> >> }
> >>
> >> But this isn't working. nginx is returning a "404" error. Here's the
> >> whole config for the server block:
> >>
> >> server {
> >> set $web_root /usr/local/www/main;
> >>
> >> listen x.x.x.x:443 default accept_filter=httpready;
> >> server_name domain.tld;
> >> access_log /var/log/httpd/nginx.access.ssl.log main buffer=4k;
> >> root $web_root;
> >>
> >> # www redirect
> >> if ($host ~* www\.(.*)) {
> >> rewrite ^(.*)$ https://domain.tld$1 permanent;
> >> }
> >>
> >> ssl on;
> >> ssl_certificate /usr/local/etc/nginx/ssl.crt;
> >> ssl_certificate_key /usr/local/etc/nginx/ssl.key;
> >> ssl_ciphers -ALL:!ADH:!NULL:!aNULL:!eNULL:HIGH;
> >> ssl_prefer_server_ciphers on;
> >> ssl_protocols SSLv3 TLSv1;
> >> ssl_verify_client off;
> >> ssl_verify_depth 1;
> >> ssl_session_cache shared:NGXSSL:1m;
> >> ssl_session_timeout 5m;
> >>
> >> # Wiki
> >> location = /wiki/ {
> >> alias /usr/local/www/skittles_wiki/;
> >> }
> >>
> >> location ~ .*\.php$ {
> >> try_files $uri /404.html;
> >> fastcgi_index index.php;
> >> fastcgi_ignore_client_abort off;
> >> fastcgi_intercept_errors off;
> >> fastcgi_pass 127.0.0.1:9000;
> >> fastcgi_read_timeout 10; # sec to wait for php-cgi to return data
> >> fastcgi_param SCRIPT_FILENAME $web_root$fastcgi_script_name;
> >> include /usr/local/etc/nginx/fastcgi_params;
> >> }
> >> }
> >
> > Frist, this
> >
> > # www redirect
> > if ($host ~* www\.(.*)) {
> > rewrite ^(.*)$ https://domain.tld$1 permanent;
> > }
> >
> > should be written as separate server:
> >
> > server {
> > server_name www.domain.tld;
> >
> > rewrite ^(.*)$ https://domain.tld$1 permanent;
> > }
> >
> > Second, "set" in
> >
> > set $web_root /usr/local/www/main;
> > ...
> > root $web_root;
> > ...
> > fastcgi_param SCRIPT_FILENAME $web_root$fastcgi_script_name;
> >
> > is just waste of CPU cycles and should be changed to
> >
> > root /usr/local/www/main;
> > ...
> > fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
> >
> > As to wiki, you need to omit "=":
> >
> > location /wiki/ {
> > alias /usr/local/www/skittles_wiki/;
> > }
> >
> >
> > --
> > Igor Sysoev
> > http://sysoev.ru/en/
> >
> >
>
> Thanks for the quick reply Igor. However, the changes don't seem to
> make any difference; I'm still getting the 404 error. After playing
> around with my configuration, it seems to be related to the try_files
> inside the "location ~ .*\.php$" block. Do you (or anyone else) know
> of a way I can solve this? It's a big confusing.
What is in error_log ?
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list