Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Alrighty.. Im having a problem where every single page is loading the same exact page in this nginx config. The page that is loading seems to be index.php

Not exactly sure what is up? It should be serving assets from disk, and redirecting php requests to index.php

My nginx vhosts:

server {
    listen 1.2.3.4:443 ssl;

    server_name xxxxxxxxxx;
    server_name xxxxxx;
    server_name xxxxxxxx;

    ssl_certificate             /usr/local/psa/var/certificates/xxxx;
    ssl_certificate_key         /usr/local/psa/var/certificates/xxxx;
    ssl_session_timeout         5m;

    ssl_protocols               SSLv2 SSLv3 TLSv1;
    ssl_ciphers                 HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

    client_max_body_size 128m;
    add_header Bryan was_here;
    root /var/www/vhosts/xxxx/httpdocs/;
    disable_symlinks off;

    location / {
        try_files $uri $uri/ /index.php?$args;
        access_log off;
    }

    #location  = / {
        #index index.php;
    #}

    # set a nice expire for assets
    location ~* "^.+\.(jpe?g|gif|css|png|js|ico|pdf|zip|tar|t?gz|mp3|wav|swf)$" {
        expires    max;
        add_header Cache-Control public;
    }

    # the downloader has its own index.php that needs to be used
    location ~* ^(/downloader|/js|/404|/report)(.*) {
        proxy_pass http://1.2.3.4:7080;

        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Accel-Internal /internal-nginx-static-location;
    }

    location ~* \.php {
        proxy_pass http://1.2.3.4:7080;

        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Accel-Internal /internal-nginx-static-location;
    }

    location /internal-nginx-static-location/ {
        alias      /var/www/vhosts/xxxx/httpdocs/;
        access_log /var/www/vhosts/xxxx/statistics/logs/proxy_access_ssl_log;
        add_header X-Powered-By PleskLin;
        internal;
    }
}

server {
    listen 1.2.3.4:443 ssl;
    server_name webmail.xxxx;

    ssl_certificate             /usr/local/psa/var/certificates/xxxx;
    ssl_certificate_key         /usr/local/psa/var/certificates/xxxx;
    ssl_session_timeout         5m;

    ssl_protocols               SSLv2 SSLv3 TLSv1;
    ssl_ciphers                 HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;
    client_max_body_size 128m;

    location / { # IPv6 isn't supported in proxy_pass yet.
        proxy_pass https://1.2.3.4:7081;

        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        access_log /var/www/vhosts/xxxx/statistics/logs/webmail_access_ssl_log;
    }
}


server {
    listen 1.2.3.4:80;

    server_name xxxx;
    server_name xxxx;
    server_name xxxx;


    client_max_body_size 128m;
    root /var/www/vhosts/xxxx/httpdocs/;
    disable_symlinks off;

    location / {
        try_files $uri $uri/ /index.php?$args;
        access_log off;
        #proxy_pass https://1.2.3.4:7081;

        #proxy_set_header Host             $host;
        #proxy_set_header X-Real-IP        $remote_addr;
        #proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;

    }
    #location  = / {
        #index index.php;
    #}

    # set a nice expire for assets
    location ~* "^.+\.(jpe?g|gif|css|png|js|ico|pdf|zip|tar|t?gz|mp3|wav|swf)$" {
        expires    max;

        add_header Cache-Control public;
    }

    # the downloader has its own index.php that needs to be used
    location ~* ^(/downloader|/js|/404|/report)(.*) {
        proxy_pass http://1.2.3.4:7080;

        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Accel-Internal /internal-nginx-static-location;
    }

    location ~* \.php {
        proxy_pass http://1.2.3.4:7080;

        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Accel-Internal /internal-nginx-static-location;
    }

    location /internal-nginx-static-location/ {
        alias      /var/www/vhosts/xxxx/httpdocs/;
        access_log /var/www/vhosts/xxxx/statistics/logs/proxy_access_log;
        internal;
    }
}


server {
    listen 1.2.3.4:80;
    server_name webmail.xxxx;

    client_max_body_size 128m;

    location / { # IPv6 isn't supported in proxy_pass yet.
        proxy_pass http://1.2.3.4:7080;

        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        access_log /var/www/vhosts/xxxx/statistics/logs/webmail_access_log;
    }
}

/etc/nginx/nginx.conf :

user  nginx;
worker_processes  1;

#error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

#pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #autoindex off;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    #tcp_nodelay        on;

    #gzip  on;
    #gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip  on;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    server_tokens off;

    include /etc/nginx/conf.d/*.conf;
}
share|improve this question
    
Replacing try_files with a proxy_pass seems to make things work.. So it has something to do with that try_files –  bryan_ruiz Jun 15 '13 at 14:57
    
" # IPv6 isn't supported in proxy_pass yet": yes it is, I'm using it to pricy ipv4 requests to ipv6 hosts. –  Melvyn Jun 18 '13 at 6:44

1 Answer 1

I'm guessing here, but your try_files arguments look wrong to me.

Try maybe rather with

/index.php?q=$uri&$args;

Moreover, could we have the error.log concerning this vhost ?

share|improve this answer
    
nothing note worthy in error log.. Im actually trying this too: try_files $uri $uri/ @handler; location @handler { ## Magento uses a common front handler rewrite / /index.php; } –  bryan_ruiz Jun 15 '13 at 15:27
    
also is it possible that for some reason its hitting the first $uri or $uri/ in try_files instead of the last redirect? –  bryan_ruiz Jun 15 '13 at 15:28
    
I would agree that the try_files looks suspicious. Please understand that instead of throwing a 404, try_files will force the use of its last argument if it exists. So, it sounds like your setup is 404'ing, but you don't see it because it uses /index.php instead. –  earthmeLon Jun 15 '13 at 20:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.