Welcome! Log In Create A New Profile

Advanced

Re: Alias in Nginx Config

July 26, 2009 03:25PM
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/
Subject Author Posted

Alias in Nginx Config

APseudoUtopia July 26, 2009 02:07PM

Re: Alias in Nginx Config

Igor Sysoev July 26, 2009 03:25PM

Re: Alias in Nginx Config

APseudoUtopia July 28, 2009 04:47PM

Re: Alias in Nginx Config

Igor Sysoev July 29, 2009 04:50AM

Re: Alias in Nginx Config

APseudoUtopia July 30, 2009 05:09PM

Re: Alias in Nginx Config

Igor Sysoev July 31, 2009 05:51AM

Re: Alias in Nginx Config

APseudoUtopia August 01, 2009 10:54AM

Re: Alias in Nginx Config

Igor Sysoev August 01, 2009 02:58PM

Re: Alias in Nginx Config

APseudoUtopia August 15, 2009 04:07PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 160
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready