nginx: run rails/passenger and wordpress with subfolder permalinks - ruby-on-rails

I need help with my nginx configuration.
I want to run a rails app and a Wordpress blog under the same domain.
Wordpress should be available under a subfolder/path.
Both are already up and running, but I cannot access blog posts.
Here is my current configuration:
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name my-secret-host.com;
passenger_enabled on;
passenger_min_instances 1;
rails_env production;
root /var/www/rails-app/current/public;
# Wordpress
location /news {
alias /var/www/wordpress/;
index index.php ;
try_files $uri $uri/ /index.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
I tried a lot.
With this variation the Rails app works as expected. Wordpress is also up and running, the admin area and the index page (/) are available.
But if I call a permalink to a post like http://my-secret-host.com/news/2017/10/permalink-test-post/ the rails app responds with an error.
Maybe the solution is stupid and simple, but all my attempts ended in other problems and errors.
Moving the rails config into a location / block didn't change anything.
With disabled rails configuration I get another error, the path to index.php is not properly configured.
[error] 7705#7705: *7 open() "/usr/share/nginx/html/index.php" failed (2: No such file or directory), client: 87.133.34.209, server: my-host.com, request: "GET /news/2017/10/test234/ HTTP/1.1", host: "my-host.com", referrer: "http://my-host.com/news/"
What you see above is a activated/linked configuration file in nginx/sites-available/.
I unlinked sites-available/default, created my own and didn't change anything in nginx.conf– expect of the rails-passenger include.

Related

How to get content of default nginx configuration file in Docker environment on Ubuntu

Does anyone can point me in the right direction
I'm trying to get the content of default nginx conf file, but I can't find it anywhere in the system.
Tried:
/usr/local/nginx/conf
/etc/nginx
/usr/local/etc/nginx
all patch are not exist
My container is up and running, it shows default nginx successful install page.
Assuming you used the official nginx container, the content is located at etc/nginx/conf.d/default.conf and it's:
root#5b67d1564b45:/# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html 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 /usr/share/nginx/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;
# 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;
#}
}
But why are you interested in this? Usually what you want to do is to use your own config, not the default one.

Nginx reverse proxy not working with Puma

I need some help setting up Nginx with Puma and Rails on Ubuntu server at Digital Ocean (already spend a lot time on this).
I have the follow settings:
/etc/nginx/nginx.conf (I remove some commented lines)
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
/etc/nginx/sites-available/test_server
upstream app {
server unix:/home/deploy/www/test_server/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name testserver.com.br www.testserver.com.br; # fake url
root /home/deploy/www/test_server/public;
try_files $uri/index.html $uri #app;
location #app {
proxy_pass http://app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
/var/log/nginx/access.log
I can see a lot of requests (from my local machine, from the server at D.O and lot of others IP's that I don't recognize).
/var/log/nginx/error.log
When I try to access www.testserver.com/index from my local desk
2018/06/02 12:21:25 [error] 27541#27541: *6 open() "/usr/share/nginx/html/index" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /index HTTP/1.1", host: "www.testserver.com.br"
Firewall
Firewall is open to Nginx HTTP/HTTP (v6)
Symbolic link in /etc/nginx/sites-enabled/test_server
lrwxrwxrwx 1 root root 39 Jun 1 16:25 /etc/nginx/sites-enabled/test_server -> /etc/nginx/sites-available/test_server
What I have until now
When I make a request to the site I got this message:
"Welcome to nginx! If you see this page, the nginx web server is successfully installed and working..."
I know Puma is working fine because I can make requests direct to the socket and it returns the correct page (Rails starts in production environment ~ all working fine).
Last considerations from my attempts
I believe that Nginx is not able to connect properly with Puma and find the right files to serve. From the error.log I can see Nginx trying to access the folder /usr/share/nginx/html/ when it should try to connect to the socket, right? Maybe permission is the problem? (I saw a lot of posts on SO with permission problems).
I don't know what else I can try.
Any additional information just ask.
Thanks in advance!
Solution
As I deleted the nginx.conf file (not on purpose) and copy from the git rep., the new file was missing the include /etc/nginx/conf.d/*.conf; and include /etc/nginx/sites-enabled/*; lines. After adding these lines inside the section Http, Nginx started serving correct.

nginx: [warn] conflicting server name ip_address on 0.0.0.0:80, ignored

I have install Nginx and Passenger using How To Deploy a Rails App with Passenger and Nginx. I did everything as per the blog. But when I reload Nginx service sudo nginx -s reload it is showing nginx: [warn] conflicting server name "ip_address" on 0.0.0.0:80, ignored
/etc/site-available/default
server {
#listen 80;
#listen [::]:80 ipv6only=on;
server_name ip_address;
passenger_enabled on;
rails_env production;
root /var/www/testapp/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
/etc/site-available/testapp
server {
listen 80 default_server;
server_name ipaddress;
passenger_enabled on;
passenger_app_env development;
root /home/iradmin/rails_project/testapp/public;
}
I don't know what I have done wrong in here. Thanks in advance.
In your /etc/sites-available/default config you have set server_name to ipaddress and in /etc/sites-available/testapp you have also given a server_name of ipaddress.
The error message states that you have a conflict because in both files - the server name is ipaddress. To resolve this error, give your servers different names. More information on Nginx server_name can be found in the official docs here.

Ruby on rails nginx gives directory of is forbidden

I have an nginx server with passenger that I am trying to run a ruby on rails app. I am using rbenv and am deploying using capistrano.
I keep getting an error message that is as follows:
directory index of "[/srv/[directory]]" is forbidden, client: [my client ip], server: [my domain], request: "GET / HTTP/1.1", host: "[my domain]"
My nginx config for the site:
server {
listen 80;
server_name [my domain];
passenger_enabled on;
rails_env production;
root /srv/[my app name]/current/public;
passenger_ruby /home/deploy/.rbenv/shims/ruby;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
passenger_enabled on;
}
location / {
passenger_enabled on;
}
}
And my config for passenger in my nginx.conf file is as follows:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rbenv/shims/ruby;

Issues with configuring a simple hhvm site (hack-site-example) with ngnix on ubuntu14.04

I followed the instructions here at https://github.com/hhvm/hack-example-site and somehow lost my way when setting up hhvm hack site on ngnix over ubunut 14.04 . Please note that I used the appropriate apt-get repo for 14.04.
However after configuring and trying to access 127.0.0.1:9000 I see an error in the /var/log/hhvm/error.log
FastCGI protocol: received an invalid record
My /etc/ngnix/sites-enabled is as follows
-rw-r--r-- 1 root root 0 Aug 30 22:01 default
lrwxrwxrwx 1 root root 44 Aug 30 22:21 hack-example-site -> /etc/nginx/sites-available/hack-example-site
The contents of /etc/ngnix/sites-available/hack-example-site is as follows:
server {
root ~/hack-example-site/hack-example-site;
index index.php;
location ~ \.php$ {
# If fastcgi backend is on another server disable this.
# Read issue #6 about this
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME ~/hack-example-site/hack-example-site/index.php
fastcgi_param ~/hack-example-site/hack-example-site $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Could someone please help me with this hhvm site running on my local host? Thanks.
Oh and please note the ngnix is installed properly and the server responds to localhost.
The configuration file /etc/nginx/sites-available/hack-example-site below:
server {
root /root/hack-example-site;
index index.php;
server_name localhost;
location ~ \.php$ {
# If fastcgi backend is on another server disable this.
# Read issue #6 about this
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME ~/hack-example-site/hack-example-
site/index.php
fastcgi_param /root/hack-example-site
$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
~
I did find a work around to test my hack scripts but not really satisfied with this. I created symbolic link
/etc/ngnix/sites-enabled/default->/etc/ngnix/sites-available/default.
Copied test.php which has simple hello world written in hack to /usr/share/nginx/html. Edit the /etc/nginx/sites-available/default as follows:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
#index index.html index.htm;
index test.php;
# Make site accessible from http://localhost/
server_name localhost;
include hhvm.conf;
Now when I visited localhost, the hackscript was executed and Helloworld was shown.
However I would have liked this to work with /etc/nginx/sites-available/hack-site-example instead of default. Not sure what is going there? Can anyone throw some light?

Resources