Solved

nginx passenger / redirect

Posted on 2014-09-08
8
504 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cannot Play Videos in IE9 4 233
asp page 5 275
Looking for Wordpress plugin for registering product and then generate a unique QR code 3 232
payment gateway plugin 7 125
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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