PHP script on AWS EC2 NGINX not working but download











up vote
0
down vote

favorite












I'm trying to set up my site in AWS ec2 using nginx. Here is my nginx.conf:



include /etc/nginx/conf.d/*.conf;

index index.php index.html index.htm;

autoindex off;

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 127.0.0.1;
root /usr/share/nginx/myproject;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

#location / {
#}

location = /index.php {
rewrite ^(.*)$ /app/index.php break;
}

location / {
if (!-e $request_filename){
rewrite ^(.*)$ /app/index.php break;
}
}

location ~ .(secret|salt|engine|inc|po|sh|bat|cmd|.*sql|theme|tpl(.php)?|xtmpl)$|^(..*|inc)$ {
deny all;
}

# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
try_files $uri =404
root /usr/share/nginx/myproject;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

}


When I access the public DNS, I got download instead of running the PHP script. Is there any problem in my nginx config?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm trying to set up my site in AWS ec2 using nginx. Here is my nginx.conf:



    include /etc/nginx/conf.d/*.conf;

    index index.php index.html index.htm;

    autoindex off;

    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name 127.0.0.1;
    root /usr/share/nginx/myproject;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    #location / {
    #}

    location = /index.php {
    rewrite ^(.*)$ /app/index.php break;
    }

    location / {
    if (!-e $request_filename){
    rewrite ^(.*)$ /app/index.php break;
    }
    }

    location ~ .(secret|salt|engine|inc|po|sh|bat|cmd|.*sql|theme|tpl(.php)?|xtmpl)$|^(..*|inc)$ {
    deny all;
    }

    # redirect server error pages to the static page /40x.html
    #
    error_page 404 /404.html;
    location = /40x.html {
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
    try_files $uri =404
    root /usr/share/nginx/myproject;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    }


    When I access the public DNS, I got download instead of running the PHP script. Is there any problem in my nginx config?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to set up my site in AWS ec2 using nginx. Here is my nginx.conf:



      include /etc/nginx/conf.d/*.conf;

      index index.php index.html index.htm;

      autoindex off;

      server {
      listen 80 default_server;
      listen [::]:80 default_server;
      server_name 127.0.0.1;
      root /usr/share/nginx/myproject;

      # Load configuration files for the default server block.
      include /etc/nginx/default.d/*.conf;

      #location / {
      #}

      location = /index.php {
      rewrite ^(.*)$ /app/index.php break;
      }

      location / {
      if (!-e $request_filename){
      rewrite ^(.*)$ /app/index.php break;
      }
      }

      location ~ .(secret|salt|engine|inc|po|sh|bat|cmd|.*sql|theme|tpl(.php)?|xtmpl)$|^(..*|inc)$ {
      deny all;
      }

      # redirect server error pages to the static page /40x.html
      #
      error_page 404 /404.html;
      location = /40x.html {
      }

      # redirect server error pages to the static page /50x.html
      #
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
      }

      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
      location ~ .php$ {
      try_files $uri =404
      root /usr/share/nginx/myproject;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
      }

      }


      When I access the public DNS, I got download instead of running the PHP script. Is there any problem in my nginx config?










      share|improve this question













      I'm trying to set up my site in AWS ec2 using nginx. Here is my nginx.conf:



      include /etc/nginx/conf.d/*.conf;

      index index.php index.html index.htm;

      autoindex off;

      server {
      listen 80 default_server;
      listen [::]:80 default_server;
      server_name 127.0.0.1;
      root /usr/share/nginx/myproject;

      # Load configuration files for the default server block.
      include /etc/nginx/default.d/*.conf;

      #location / {
      #}

      location = /index.php {
      rewrite ^(.*)$ /app/index.php break;
      }

      location / {
      if (!-e $request_filename){
      rewrite ^(.*)$ /app/index.php break;
      }
      }

      location ~ .(secret|salt|engine|inc|po|sh|bat|cmd|.*sql|theme|tpl(.php)?|xtmpl)$|^(..*|inc)$ {
      deny all;
      }

      # redirect server error pages to the static page /40x.html
      #
      error_page 404 /404.html;
      location = /40x.html {
      }

      # redirect server error pages to the static page /50x.html
      #
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
      }

      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
      location ~ .php$ {
      try_files $uri =404
      root /usr/share/nginx/myproject;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
      }

      }


      When I access the public DNS, I got download instead of running the PHP script. Is there any problem in my nginx config?







      php nginx amazon-ec2






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 17 at 6:27









      Sithu

      3,02653679




      3,02653679
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          Your rewrite...break statements should be rewrite...last as the PHP file needs to be processed in a different location. See this document for details.



          For example:



          location / {
          if (!-e $request_filename){
          rewrite ^ /app/index.php last;
          }
          }


          However, the above functionality is usually implemented as:



          location / {
          try_files $uri $uri/ /app/index.php;
          }




          Other issues include:




          • a missing ; in the location ~ .php$ block following the try_files statement.


          • the root statement in the location ~ .php$ block should be deleted, as it is unnecessary.







          share|improve this answer





















          • no luck, still getting download
            – Sithu
            Nov 17 at 17:08











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348827%2fphp-script-on-aws-ec2-nginx-not-working-but-download%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          Your rewrite...break statements should be rewrite...last as the PHP file needs to be processed in a different location. See this document for details.



          For example:



          location / {
          if (!-e $request_filename){
          rewrite ^ /app/index.php last;
          }
          }


          However, the above functionality is usually implemented as:



          location / {
          try_files $uri $uri/ /app/index.php;
          }




          Other issues include:




          • a missing ; in the location ~ .php$ block following the try_files statement.


          • the root statement in the location ~ .php$ block should be deleted, as it is unnecessary.







          share|improve this answer





















          • no luck, still getting download
            – Sithu
            Nov 17 at 17:08















          up vote
          1
          down vote













          Your rewrite...break statements should be rewrite...last as the PHP file needs to be processed in a different location. See this document for details.



          For example:



          location / {
          if (!-e $request_filename){
          rewrite ^ /app/index.php last;
          }
          }


          However, the above functionality is usually implemented as:



          location / {
          try_files $uri $uri/ /app/index.php;
          }




          Other issues include:




          • a missing ; in the location ~ .php$ block following the try_files statement.


          • the root statement in the location ~ .php$ block should be deleted, as it is unnecessary.







          share|improve this answer





















          • no luck, still getting download
            – Sithu
            Nov 17 at 17:08













          up vote
          1
          down vote










          up vote
          1
          down vote









          Your rewrite...break statements should be rewrite...last as the PHP file needs to be processed in a different location. See this document for details.



          For example:



          location / {
          if (!-e $request_filename){
          rewrite ^ /app/index.php last;
          }
          }


          However, the above functionality is usually implemented as:



          location / {
          try_files $uri $uri/ /app/index.php;
          }




          Other issues include:




          • a missing ; in the location ~ .php$ block following the try_files statement.


          • the root statement in the location ~ .php$ block should be deleted, as it is unnecessary.







          share|improve this answer












          Your rewrite...break statements should be rewrite...last as the PHP file needs to be processed in a different location. See this document for details.



          For example:



          location / {
          if (!-e $request_filename){
          rewrite ^ /app/index.php last;
          }
          }


          However, the above functionality is usually implemented as:



          location / {
          try_files $uri $uri/ /app/index.php;
          }




          Other issues include:




          • a missing ; in the location ~ .php$ block following the try_files statement.


          • the root statement in the location ~ .php$ block should be deleted, as it is unnecessary.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 17 at 9:41









          Richard Smith

          18.8k32137




          18.8k32137












          • no luck, still getting download
            – Sithu
            Nov 17 at 17:08


















          • no luck, still getting download
            – Sithu
            Nov 17 at 17:08
















          no luck, still getting download
          – Sithu
          Nov 17 at 17:08




          no luck, still getting download
          – Sithu
          Nov 17 at 17:08


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348827%2fphp-script-on-aws-ec2-nginx-not-working-but-download%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]