Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

nginx passenger / redirect

Posted on 2014-09-08
8
Medium Priority
?
639 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 58

Expert Comment

by:Gary
ID: 40310875
And you have an extra squiggly at the end as well
0
 
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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

885 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