Linking nginx config with installing - shell

I am trying to install nginx with a shell script but it seems like I have made a mistake:
# INSTALL NGINX
apt-get install nginx
# LINK CONFIGURATION FILE
ln -fs /etc/configuration/nginx/nginx/app.conf /etc/nginx/sites-available/app
ln -fs /etc/configuration/nginx/nginx/nginx.conf /etc/nginx/nginx.conf
# RESTART
service nginx restart
My configuration for my app.conf is as such:
server {
listen 80;
root /home/deploy/project123;
server_name www.project123.com;
location / { try_files $uri #app; }
location #app {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.sock;
}
}
My nginx.conf is such:
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
My code is in: /home/deploy/project123
When I visit the site I get a 404 as if nothing is running. Can anyone tell me what I have done wrong please?

ln -fs /etc/configuration/nginx/nginx/app.conf /etc/nginx/sites-available/app
You need to link it to sites-enabled and not available - and it will probably work for you.
I would also not change the name of the conf-file, for clarity:
ln -fs /etc/configuration/nginx/nginx/app.conf /etc/nginx/sites-enabled/
would make it work
Looks like you are doing some configuration management of your own, have you check out puppet, chef, cfengine, saltstack?

Related

Laravel - Laravel Deployment failed on DigitalOcean

I deployed my Laravel-5.8 to Digital Ocean.
/etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html/peopleedge;
# Add index.php to the list if you are using PHP
# index index.php index.html index.htm;
# index index.php index.html index.htm index.nginx-debian.html;
server_name 123.130.32.49;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php$is_args$args;
# try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
When I tried to open the site, I got this error:
Secondly, my am I seeing htdocs on my online server since I deployed to DigitalOcean:
There is no existing directory at "C:\xampp\htdocs\peopleedge\storage\logs" and its not buildable: Permission denied
I run all these commands, but the problems still persists:
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
sudo chmod -R 755 /var/www/html/peopleedge
sudo chmod -R o+w /var/www/html/peopleedge/storage/
How do I resolve it?
Thank you

Nginx only serving static files for a Sinatra application

I'm trying to run ruby (sinatra) script under the Nginx.
My folder structure is:
/www (775)
/www/public (775)
/www/public/img.jpg (644)
/www/app.rb (775)
/www/index.html (775)
My nginx.conf is:
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /home/my_user/.rvm/gems/ruby-2.4.1/gems/passenger-5.1.6;
passenger_ruby /home/my_user/.rvm/gems/ruby-2.4.1/wrappers/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
server_name xxx.xxx.xx.xx;
root /www/public;
passenger_enabled on;
}
}
But I'm getting served just a xxx.xxx.xx.xx/img.jpg, no script.
xxx.xxx.xx.xx/index.html gives me error 404 and xxx.xxx.xx.xx gives me error 403 again.
Is important under which user is nginx server running (folder /www and files inside it have a different user than the user running nginx).
Thanks
So thanks to #tadman the configuration was ok, the problem was just missing config.ru file.

how to configure nginx with magento on ubuntu localhost

i need to install magento 1.8 and 1.9 on ubuntu on nginx server.
i created configuration but is not working fine.
i need to create one global configuration files for magento 1.8, magento 1.9
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
# With php5-fpm:
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
You state in the comments that you get a 403 forbidden message. There's a number of things that could be causing this. You will find more information on this error by checking the nginx error logs which are by default kept in /var/log/nginx/*.log
I'd strongly recommend checking the error logs for further information as it will speed up the process of fixing the issue.
1. Incorrect web root
An obvious one but just make sure you have the correct web root set
$ ls /usr/share/nginx/html
2. Directory and File Permissions
Check your web user (normally www-data on Ubuntu/Debian) is allowed permissions to access the files in the web directory aswerll as the directory itself. Check the permissions by running on terminal:
$ ls -l /usr/share/nginx/html
Make sure the files have the right permissions set and aren't, for example, set to root ownership.
Magento has instructions on resetting the file permissions for your Magento install here. In summary run the following on the terminal:
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod 550 pear
chmod 550 mage #for magento 1.5+

How do I create multiple locations with Nginx, Passenger, Sinatra

I have a server section that looks like:
server {
listen 80;
server_name arch;
root /data/apps/production/fentonGem2/current/public;
passenger_enabled on;
}
which works fine. However, I'd like to deploy two or more apps to the same server_name and listen port. So presumably I'd use something like the following:
server {
listen 80;
server_name arch;
location /app1 {
root /data/apps/production/fentonGem2/current/public;
passenger_enabled on;
}
location /app2 {
root /data/apps/production/fentonGem3/current/public;
passenger_enabled on
}
}
But that doesn't work. Does anyone know how I can deploy two separate apps, and reach them by:
http://domain.com/app1/
and:
http://domain.com/app2/
The setup uses Nginx, Phusion Passenger, Rack, and Sinatra.
UPDATE:
Thanks for the responses, but I found them and the approach not helpful, though maybe I'm not understanding it well. It kind of seems like I have to deploy one application inside another, which seems very unclean. What I finally resorted to was having separate server sections, and then updating my /etc/hosts file to have server aliases for the same IP address. So now I have:
http://app1/
and:
http://app2/
and server sections that look like:
server {
listen 80;
server_name app1;
root /data/apps/production/app1/current/public;
passenger_enabled on;
}
server {
listen 80;
server_name app2;
root /data/apps/production/app2/current/public;
passenger_enabled on;
}
and in /etc/hosts:
192.168.1.30 app1 app2
The following worked:
First made symlinks named app1 and app2 pointing to the "public" directory as follows:
ln -s /data/apps/production/fentonGem2/current/public /data/apps/production/fentonGem2/current/app1
ln -s /data/apps/production/fentonGem2/current/public /data/apps/production/fentonGem2/current/app2
Modify nginx.conf to have rails_base_uri, which should look something like the following:
...
server {
listen 80;
server_name arch;
location ^~ /app1 {
root /data/apps/production/fentonGem2/current;
rails_env production;
passenger_enabled on;
passenger_base_uri /app1;
}
location ^~ /app2 {
root /data/apps/production/fentonGem2/current;
rails_env production;
passenger_enabled on;
passenger_base_uri /app2;
}
}
...
Hope this helps.
Not sure, but you might need passenger_base_uri /app1;
More about Passenger and Nginx conf:
http://www.modrails.com/documentation/Users%20guide%20Nginx.html#PassengerBaseURI
EDIT:
"It is allowed to specify this option multiple times. Do this to deploy multiple applications in different sub-URIs under the same virtual host."

How do I configure nginx and CodeIgniter?

I'm running nginx on my home computer for development. I also have it linked to DynDNS so I can show progress to my co-worker a bit easier. I can't seem to get nginx to rewrite to CodeIgniter properly. I have CodeIgniters uri_protocol set to REQUEST_URI.
All pages that should be showing up wtih content show up completely blank. If I phpinfo(); die(); in the index.php file of Codeigniter, it works as expected and I get the phpinfo.
Also, pages that should give a 404 give a proper CodeIgniter 404 error.
Here's what I have so far.
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
#gzip on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
root /home/zack/Development/public_html;
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name zackhovatter.dyndns.info;
index index.php;
root /home/zack/Development/public_html;
location /codeigniter/ {
if (!-e $request_filename) {
rewrite ^/codeigniter/(.*)$ /codeigniter/index.php/$1 last;
}
}
#this is for the index.php in the root folder
location /index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/zack/Development/public_html/index.php;
include fastcgi_params;
}
location /codeigniter/index.php {
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/zack/Development/public_html/codeigniter/index.php;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param PATH_INFO $document_uri;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass 127.0.0.1:9000;
}
}
}
Actually I got this working. Not sure how, but I think it was file permissions being set incorrectly or something.
Edit:
For those who are wondering, I had an older version of PHP installed it seems. Reverting back to old class constructors fixed the issue. Darnit.
I have exactly the same problem (Codeigniter gives blank pages and the error pages and php are working) and i found that the problem was from the mysql db driver which should be changed to mysqli driver .
So just we need to change the db driver in config/database.php
$db['default']['dbdriver'] = 'mysqli';
And this is due that the mysql driver is deprecated in the new versions of php.
CodeIgniter4 How To Setup NGINX Server Blocks (Virtual Hosts) on RasperyPi Debian 10.4
I am using a RasperyPi-4 as web developing server with different projects running on it.
Visual Studio Code enables editing files via Remote-SSH extension very easily.
Setting up CI4 on NGINX gives you the opportunity to run different projects on the same server.
Because it took me some days to get this configuration running I will give you a quick reference guide to setup quick and easy.
If you have not installed NGINX and composer yet please have a look here:
http://nginx.org/en/docs/beginners_guide.html
https://codeigniter4.github.io/userguide/installation/installing_composer.html
https://getcomposer.org/download/
CodeIgniter4 installation via composer
server ip: 10.0.0.10
port: 8085
project name is 'test'
Please modify to your needs!
cd /var/www/html
composer create-project codeigniter4/appstarter test
the command above will create a 'test' folder /var/www/html/test
Modify the 'env' file
sudo nano /var/www/html/test/env
app.baseURL = 'http://10.0.0.10:8085'
Important: Do NOT use 'localhost' for the server URL!!!!!
please uncomment:
# CI_ENVIRONMENT = production
and modify:
CI_ENVIRONMENT = development
Save the file as '.env' to hide the file
NGINX Server Blocks
cd /etc/nginx/sites-available
touch test
sudo nano test
Paste this into the file and save after modifying to your requirements:
server {
listen 8085;
listen [::]:8085;
server_name test;
root /var/www/html/test/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm:
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# With php-cgi:
# fastcgi_pass 127.0.0.1:9000;
}
error_page 404 /index.php;
# deny access to hidden files such as .htaccess
location ~ /\. {
deny all;
}
}
After saving the file create a symbolic link to sites-enabled:
cd /etc/nginx/sites-enabled
sudo ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/test
Modify File and Group Permissions
chown -v -R pi:www-data /var/www/html/test
sudo chmod -v -R 775 /var/www/html/test
Start NGINX
sudo service nginx start
Open CI4 Welcome Page
http://10.0.0.10:8085
Here is a solution.
https://web.archive.org/web/20120504010725/http://hiteshjoshi.com/linux/secure-nginx-and-codeigniter-configuration.html
Also, I had to change $config['uri_protocol'] = “DOCUMENT_URI”; to make it work.
UPDATE: Fixed the 404 url from web archive.

Resources