I have Nginx server. Currently, I have two projects:
- www.xyz.com -> /var/www/project/public; (This is working)
- www.xyz.com/blog -> /var/www/blog; (Error: This webpage has a redirect loop)
How can I point both to the above folders. I tried the following code.
server {
listen 80;
server_name xyz.com;
rewrite ^/(.*)/$ /$1 permanent;
return 301 $scheme://www.xyz.com$request_uri;
}
server {
listen 80 default_server;
server_name www.xyz.com;
rewrite ^/(.*)/$ /$1 permanent;
root /var/www/project/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location ~* \.(pdf)$ {
expires 30d;
}
location ~ \.(?:css|htc|js|js2|js3|js4)$ {
gzip_vary on;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /blog {
root /var/www/blog;
}
location ~ /blog/.+\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/blog$fastcgi_script_name;
}
}