Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

this is what I did with the standard nginx.conf

if I use port I have no problem, but if I do localhost or it's alias it always downloads something?

I cannot seem to set a virtualhost name and just have it working.

thanks for any suggestions.

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
error_log /var/log/nginx-error.log debug;

#pid        logs/;

events {
    worker_connections  1024;

http {
    include       mime.types;

   # include /usr/local/etc/nginx/conf.d/*.conf;
    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  logs/access.log  main;
error_log /var/log/nginx-error.log debug;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    listen       80;
    root /Users/redres/Webdev/nodejsphp;
    index index.phtml;

    server_name localhost;
    location / {
    location = /favicon.ico {
            log_not_found off;
            access_log off;

    server {
        listen       8060;
       # server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
          #  root   html;
    root /Users/redres/Webdev/nodejsphp;
            index  index.html index.php index.htm;

        #error_page  404              /404.html;

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

        # proxy the PHP scripts to Apache listening on
        #location ~ \.php$ {
        #    proxy_pass;

        # pass the PHP scripts to FastCGI server listening on
        location ~ \.php$ {
        #    root           html;
    root /Users/redres/Webdev/nodejsphp;
fastcgi_pass   unix:/tmp/php-fpm.socket;            
fastcgi_index  index.php;
           # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #location ~ /\.ht {
        #    deny  all;
share|improve this question
up vote 1 down vote accepted

I guess the port is a red-herring, and the specific problem is that your browser doesn't know how to handle a file with a .phtml suffix.

Can you post curl outputs when you have the server running on each port, to rule that out?

Something like this might be instructive:

$ curl -v http://localhost/

$ curl -v

(For example you might see a response from apache on port 80, if that is already listening..?)

share|improve this answer
it is returning ok, except for the octet/stream header, and that was kind of my question also. ( why it does not do that with the second server block). to only defaults to the first server block. only goes to the right place. What is a red-herring again? – Richard Sep 29 '13 at 18:00
Apache is not running! I have read another post with the solution of removing apache and php then reinstall php, but I do not want to do that yet. oh and removing the .phtml and just use .html will not solve it. – Richard Sep 29 '13 at 18:19
If the MIME-type is wrong that is because nginx doesn't recognize the extension. Fix that by either using "types" inside nginx, or updating the mime.types file that nginx is using - probably /etc/mime.types. – Steve Kemp Sep 29 '13 at 18:33
thanks both, finally it starts to work. It is something to get used too I guess. One thing, I did .html also, could it be something related to browser caching or refreshing that it was not inmediatly responding to my changes? because now it seems so simple, but it was very annoying for a while, because I had the same settings before? If I new what it was, I could watch out for that. – Richard Sep 29 '13 at 18:50
ah, I just read it after two days on the bottom off the page – Richard Sep 29 '13 at 19:51

It's sending an octet-stream because it doesn't know what a phtml file is.

Add phtml to the mime.types file in the text/html line so that it sends the right mime type:

The second server block doesn't point to a phtml file and hence you won't get the download.

        text/html                               html htm shtml phtml;

Then it should send a header that your browser will like to display instead of download.

share|improve this answer

Your Answer


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.