Solved

nginx passenger / redirect

Posted on 2014-09-08
8
475 Views
Last Modified: 2014-09-09
https://www.digitalocean.com/community/tutorials/how-to-deploy-rails-apps-using-passenger-with-nginx-on-centos-6-5
I followed this page to get my rails environment working, and its working good but I want a separate area for non rails development. How do I setup a virtual host so that the passenger module is bypassed and nginx opens my non ruby/rails page?

my http://x.x.x.x/tasks is working but this is a ruby web app and delivers content from /var/www/my_app

I want to hit http://x.x.x.x/sipml5 and the nginx webserver display the content from /var/www/sipml5

here's my current nginx.conf file:

[root@p3660712 conf]# vi nginx.conf
#        location / {
#            root   html;
#            index  index.html index.htm;
#        }

        root /var/www/my_app/public;
        passenger_enabled on;

        #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;
        }

    server {
        listen  80;
        server_name sipml5;
        location / {
                root html;
                index index.html index.htm;
                }
        root /var/www/sipml5/;
        }

Open in new window


and here's what I get when I try to restart nginx

[root@p3660712 conf]# /etc/init.d/nginx restart
nginx: [emerg] "server" directive is not allowed here in /opt/nginx/conf/nginx.conf:64
nginx: configuration file /opt/nginx/conf/nginx.conf test failed
0
Comment
Question by:Dalexan
  • 5
  • 3
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40310865
Is that the whole conf file? Guessing not by the error line no.
Check you have closed the squigglies off correctly, I would guess it is missing from just before your new server line since location should be in a server block.
0
 

Author Comment

by:Dalexan
ID: 40310870
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /home/it/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.48;
    passenger_ruby /home/it/.rvm/gems/ruby-2.1.2/wrappers/ruby;
    passenger_app_env development;

    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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

#        location / {
#            root   html;
#            index  index.html index.htm;
#        }

        root /var/www/my_app/public;
        passenger_enabled on;

        #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;
        }

    server {
        listen  80;
        server_name sipml5;
        location / {
                root html;
                index index.html index.htm;
                }
        root /var/www/sipml5/;
        }

        # 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;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40310872
As I said you are missing a squiggly } before your other server block
0
 
LVL 58

Expert Comment

by:Gary
ID: 40310875
And you have an extra squiggly at the end as well
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 58

Expert Comment

by:Gary
ID: 40310876
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /home/it/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.48;
    passenger_ruby /home/it/.rvm/gems/ruby-2.1.2/wrappers/ruby;
    passenger_app_env development;

    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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

#        location / {
#            root   html;
#            index  index.html index.htm;
#        }

        root /var/www/my_app/public;
        passenger_enabled on;

        #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;
        }
    }

    server {
        listen  80;
        server_name sipml5;
        location / {
                root html;
                index index.html index.htm;
                }
        root /var/www/sipml5/;
        }

        # 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;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
        #}


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Open in new window

0
 

Author Comment

by:Dalexan
ID: 40310881
That was it, I had the server within the previous server element. Updated and restarted but its still not showing what I'm after, seems the rails framework is still trapping the output

    server {
        listen  80;
        server_name sipml5;
        location / {
                root html;
                index index.html index.htm;
                }
        root /var/www/sipml5/;
        }

When I hit http://x.x.x.x/sipml5/ i get the rails routing error page
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40310886
Your first server block is a catch all.
Move your Ruby server block so it is first.
0
 

Author Closing Comment

by:Dalexan
ID: 40312093
Thank you, this is my first go at using nginx.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now