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

this is what I did with the standard nginx.conf

if I use port boo.dev:8060 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/nginx.pid;


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;

server{
    listen       80;
    #listen     njsphp.dev;
    root /Users/redres/Webdev/nodejsphp;
    index index.phtml;

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


    server {
        listen       8060;
       # server_name  localhost;
       server_name  boo.dev;



        #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 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
        #    root           html;
    root /Users/redres/Webdev/nodejsphp;
            #fastcgi_pass   127.0.0.1:9000;
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
add comment

2 Answers

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 http://boo.dev/

(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 boo.dev only defaults to the first server block. only boo.dev:8060 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
1  
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 wiki.nginx.org/Pitfalls –  Richard Sep 29 '13 at 19:51
add comment

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
add comment

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.