uwsgi / mod_wsgi handling pylons redirect_to & error pages - pylons

My stack is nginx > uwsgi > pylons.
If I use redirect_to on a controller, the app throws a 302 error. Also I don't see any 404 or 500 error pages anymore that worked fine in paste.
Any pointers would be greatly appreciated.
Thanks.

uwsgi_param SCRIPT_NAME '';
Add that to your nginx config.

Related

unicorn production configuration

I see my unicorn error file growing, and I can't find out why.
It log some path but when I try them on my browser, I don't see any issue neither redirection.
I'm using rails and this is a snippet of my unicorn production conf file:
stderr_path "log/unicorn.error.log"
stdout_path "log/unicorn.log"
One line from the error log file:
xxx.xxx.xxx.xxx, yyy.yyy.yyy - - [16/Mar/2019:20:13:54 +0100] "GET /fr/yyyyyyy HTTP/1.0" 200 - 0.0926
I thought 200 means that it was OK, but why do I see HTTP/1.0 when my site is only https?
More over, why do I get all those log entries when all the reported errors are working correctly for me?
Is there a way to format log so that I can get more info on error?
HTTP/1.0 is the protocol, this does not imply that your site is not using HTTPS.
By default, the Unicorn logger will write to stderr. So these are not errors, just logs of requests coming in.
Refer this for unicorn configuration options and their meanings - https://github.com/phusion/unicorn/blob/master/examples/unicorn.conf.rb

Rails: Why does my server redirect http to https

I have a rails app that I had built on Heroku and I had configured it to use SSL there. Now I'm moving to AWS EC2 and I want to get a version of my app working without SSL. Once that is done I will add the SSL functionality later.
My stack is Puma + Nginx + PostgreSQL and I'm working with Rails 4.2.4, Ruby 2.2.3 and Capistrano 3.4.0.
I remember in my app that I had once inserted the line
config.force_ssl = true
in config/environments/production.rb. I commented this out expecting my app to go back to working well with http. But it didn't: even after commenting that line, whenever I visit my EC2 public IP (52.35.82.113) the request gets sent on port 80 (http) and gets redirected to port 443 (https).
This can be seen more clearly when I run curl -v http://localhost on my EC2 instance it returns:
* Rebuilt URL to: http://localhost/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
* Server nginx/1.4.6 (Ubuntu) is not blacklisted
< Server: nginx/1.4.6 (Ubuntu)
< Date: Sat, 12 Dec 2015 12:22:56 GMT
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
< Location: https://localhost/
<
* Connection #0 to host localhost left intact
I'm not very experienced when it comes to this stuff. I thought initially the problem would be with my Nginx configuration, in my previous question here it was suggested to me that there was nothing wrong with my Nginx config and that the redirect was coming from Rails. I suspect this is the case since I can't see anything in Nginx that could be enforcing the redirect, but if you think the issue might be there then you can see a lot of the relevant code in the link above.
What else in Rails apart from the force_ssl printed above could be causing the redirect?
Thanks for your help everyone. Let me know if you have any questions or need more info!
This gist suggests it might be because of an HSTS header:
So if you enabled force_ssl once, even [if] you change the config value to false later, the browser you used to open you[r] app before will still remember this website (using domain to identify) [and] require [you] to use HTTPS, and redirect you to HTTPS connection automatically.
According to this page you can remove your HSTS entries by going to chrome://net-internals/#hsts in Chrome and about:permissions in Firefox and deleting ~/Library/Cookies/HSTS.plist in Safari.
In Rails you can force site wide SSL using a config file(like you were doing) or you can pick which endpoints will use SSL and use the force_ssl class method at the controller level.
Maybe you used that method on your application_controller.rb or which ever controller is serving the root path and forgot about it. You may find an exemple of such mechanism within Rails docs: http://api.rubyonrails.org/classes/ActionController/ForceSSL/ClassMethods.html
force_ssl(options = {}) Link Force the request to this particular
controller or specified actions to be under HTTPS protocol.
If you need to disable this for any reason (e.g. development) then you
can use an :if or :unless condition.
class AccountsController < ApplicationController
force_ssl if: :ssl_configured?
def ssl_configured?
!Rails.env.development?
end
end
I tried before to comment this line in production server and it didn't change anything so instead of commenting just change true to false like:
config.force_ssl = false
I experienced this problem too (rails + puma + nginx). Every redirect_to was sent to https, even if coming from http.
In the vhost.conf there was this line:
proxy_set_header X-Forwarded-Proto https;
redirect_to worked properly after changing that to
proxy_set_header X-Forwarded-Proto http;
I had the same problem. Solution for me was:
Delete config.force_ssl = true from aplication.rb
For ubuntu Ctrl + Shift + Del => Clear browsing data
in my case this setting in nginx config was the reason of issue
proxy_set_header X-Forwarded-Ssl on;
make sure that your config does not contain same setting

403 forbidden on rails + nginx + passenger

I recently updated ubuntu on my server and since then have had a 403 forbidden. Here is the nginx.conf:
https://gist.github.com/anonymous/11016133
and here are the permissions on the rails/www directory:
https://gist.github.com/anonymous/11016213
Could really use some help, thanks.
This could be because of many reasons, please see this post and hopefully it would help you resolve your issue: http://thelazylog.com/posts/how-to-fix-403-fobidden-issue-on-nginx-rails-application

custom 404 not work in Nginx + Passenger fr Rails

My Rails server environment is Nginx with Passenger and works fine so far.
Now I want to customize the 404 page, so I changed the nginx configuration like this:
...
error_page 404 /404.html;
...
Unfortunately it's not working. Does Passenger affect this?
If you want that nginx handles the error pages, then you need to set the option passenger_intercept_errors to on. After that change you can use the normal error_page option of nginx.
Maybe you also want to set passenger_friendly_error_pages to off, so you could create your own start up messages.
As #Dominik mentioned, you need to put your custom error pages (404.html) into the public/ folder of your app root.
in rails you simply put your 404.html in the public folder of your app (where the document root is too)

Forbidden 403 - Rails App

Some help would be appreciated - keep getting Forbidden 403 error.
Nginx configuration:
listen 80;
server_name www.xxx.com;
passenger_enabled on;
#charset koi8-r;
#access_log logs/host.access.log main;
root /home/deploy/xxx.com/current;
I've deployed with Capistrano, and it was successful (cap deploy)
I've googled and not found much help, from those that I tried.
Secondly, I've removed my "public" folder, and enabled my "route" in routes.rb.
root to: 'static_pages#home'
Origionally I had the "public" folder in place, but it kept going to "index.html", not the Rails /Home. I've tried this locally and it works perfectly with "rails server" on localhost:3000.
It almost appears as if NGINX does not now how to find or serve up the Rails pages.
Ps. I did review StackOverflow, not luck there.
Any help would be appreciated.
Yihhaaaaa ok got it!
The problem seemed to be two things as mentioned in the comments:
(a) Pre-compilation error; "images" were not loading. Went into
config/environments/production.db and turned on "true" for asset
compilation.
(b) Second thing was because I was developing on Mac OS X, a Javascript Runtime is included by default, whereas my production
Ubuntu not so. So I added to GemFile - gem "therubyracer".
And what do you know it works!
The key was looking in the production.log (/home/deploy/xxx.com/current/log/).
That shall tell all.
Cheers
There are several reasons related to this error, please check this post for more details: http://thelazylog.com/posts/how-to-fix-403-fobidden-issue-on-nginx-rails-application

Resources