I Have installed Nginx-full via homebrew to the latests stable 1.8.1 version. I have installed php7.0 via brew as well. I want to get php working but i can't first get nginx to serve a static file. I have this configuration on a server and works perfectly but on my mac I'm having trouble. I set up my sites directory as follows:
nginx.conf:
#user www-data www-data;
worker_processes 4;
events {
worker_connections 1024;
}
http {
include mime.types;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
/sites-available/default
server {
listen 80;
server_name localhost;
root /Users/londreblocker/Developer/Sites/bootstrap;
index index.php
error_log /Users/londreblocker/Logs/DMFA_erros.log;
access_log
/Users/londreblocker/Logs/DMFA_access.log;
}
there is a symbolic link to default in the sites-enabled folder. When i try to connect all i get is
This webpage is not available
ERR_CONNECTION_REFUSED
Any idea what could be going wrong. I am on a mac with El Capitan.
Check if nginx configuration is correct:
sudo nginx -t
and your config symlinks not broken:
ls -al /etc/nginx/sites-enabled
Check if nginx running:
ps aux |grep nginx
Check if nginx listening port 80:
sudo lsof -i -P | grep -i "listen"
If anyone is interested in my solution.
I had more than one version of nginx running due to previous install attempts and incorrect uninstalls. I deleted all versions and then did a reinstall. Seems to be working now.
Related
I installed nginx using brew install nginx
Screenshot of the terminal commands and their results
I started nginx using brew services start nginx
I changed the usr/local/etc/nginx/nginx.conf file to add a new location and i changed the user to mobi staff
I added
location /p1/ {
proxy_pass http://127.0.0.1:5000/api/product;
}
location /p2/ {
proxy_pass http://www.google.com;
}
Neither of the proxy pass things are working, i added the google.com one to test if it would work but when i go to localhost:8080/p1/ or localhost:8080/p2/ i get a 404 not found. How do I fix this so I can setup a reverse proxy that will go to those links?
Screen shot of the install and nginx.conf
I figured it out, I moved the
location /p1/ {
proxy_pass http://127.0.0.1:5000/api/product;
}
location /p2/ {
proxy_pass http://www.google.com;
}
code to be just below the server
server {
listen 8080;
server_name localhost;
location /p1/ {
proxy_pass http://127.0.0.1:5000/api/product;
}
location /p2/ {
proxy_pass http://www.google.com;
}
and then instead of running
sudo brew services restart nginx
I ran
brew services restart nginx
and it works i get redirected to the urls now!
Install Nginx on Mac local with brew install nginx. I don’t know why nginx local does not have the conf.d folder and the contents in it. (If you use docker run, there will be /etc/nginx/conf.d/default.conf
But in Mac local I don’t know why there is no
The main configuration in nginx docker access_log /var/log/nginx/access.log main in nginx.conf; is open, open access.log but there is nothing there, while local nginx has something as soon as it is opened (and The access_log /var/log/nginx/access.log in local nginx.conf is actually a comment by default)
Later, I found that there is a line in default.conf in nginx docker #access_log /var/log/nginx/host.access.log main; Is this to be turned on?
And in nginx docker, nginx.conf has access_log /var/log/nginx/access.log main; but there is still no log. When will this line be used?
i think the location for the nginx configuration file on mac is different.
try to check in
/usr/local/etc/nginx/
I am adding https support to our servers. How can I not stop Nginx when adding Let's Encrypt support?
Add this block to your server configuration (depending on your server configuration you can use other path than /var/www/html):
location ~ /.well-known {
root /var/www/html;
allow all;
}
Reload nginx, run certbot as follows:
certbot certonly -a webroot --webroot-path=/var/www/html -d yourdomain.example
Apply generated certificate to your server configuration
ssl_certificate /etc/letsencrypt/live/yourdomain.example/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.example/privkey.pem;
Make sure server setup is configured to run on port 443 with ssl:
listen 443 ssl;
Reload nginx again. Between reloads, you can make sure if configuration don't have syntax errors by running nginx -t.
against all answers you can run certbot in nginx mode.
just read the docs for it.
all you have to do is install an additional nginx plugin and follow the docs of certbot.
that plugin would even hot reload the cached certificates in nginx ram as soon as they get updated.
https://certbot.eff.org/instructions
or go to the nginx docs instead: https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/
You can use docker for that. Link on hub.docker
For example:
Create certbot.sh
For that you must run in CLI:
touch certbot.sh && chmod +x ./certbot.sh
Write in file:
#!/usr/bin/env bash
docker run --rm -v /etc/letsencrypt:/etc/letsencrypt -v /var/lib/letsencrypt:/var/lib/letsencrypt certbot/certbot "$#"
and run like this:
./certbot.sh --webroot -w /var/www/example -d example.com -d www.example.com -w /var/www/thing -d thing.is -d m.thing.is
OR
./certbot.sh renew
And you can add call this method in crontab for renew
0 0 1 * * /<PATH_TO_FILE>/certbot.sh renew
I've set up a new macbook pro with El Capitan, I used homebrew to install everything. Also using brew services to start and stop launchctl.
I'm not sure what the problem is, I have it working on my iMac and did the same thing on the MBP, the config file is untouched, so I should be getting the default welcome screen on localhost, server_name is set to localhost
Any suggestions?
So the fix was adding [::]:8080 to the nginx.conf file
I used sudo lsof -i TCP -Pn | grep nginx and saw it
was listening for ipv6 like #ZYWJ was hinting at.
So your nginx.conf file should look something like this:
server {
listen [::]:8080;
server_name localhost;
}
I installed with homebrew
I hope this helps anyone with the same problem.
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?