Nginx mac os big sur

jimothyGator / README.md

  • nginx.conf to /usr/local/etc/nginx/
  • default.conf and default-ssl.conf to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/

Not documented yet:

  • How to create self-signed SSL certificates
  • How to start and stop Nginx
server <
listen 443;
server_name localhost;
ssl on;
ssl_certificate server.crt;
ssl_certificate_key server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / <
root html;
index index.html index.htm;
>
>
server <
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
location / <
root 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 html;
>
>
xml version = » 1.0 » encoding = » UTF-8 » ?>
DOCTYPE plist PUBLIC «-//Apple//DTD PLIST 1.0//EN» «http://www.apple.com/DTDs/PropertyList-1.0.dtd»>
plist version = » 1.0 » >
dict >
key > Label key >
string > homebrew.mxcl.nginx string >
key > RunAtLoad key >
true/>
key > KeepAlive key >
false/>
key > ProgramArguments key >
array >
string > /usr/local/opt/nginx/sbin/nginx string >
string > -g string >
string > daemon off; string >
array >
key > WorkingDirectory key >
string > /usr/local string >
dict >
plist >
#user nobody;
worker_processes 1 ;
error_log /Library/Logs/nginx/error.log;
events <
worker_connections 1024 ;
>
http <
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 /Library/Logs/nginx/access.log main ;
sendfile on ;
keepalive_timeout 65 ;
index index.html index.php;
upstream www-upstream-pool <
server unix:/tmp/php-fpm.sock;
>
include /etc/nginx/conf.d/*.conf;
include /usr/local/etc/nginx/sites-enabled/*.conf;
>

This comment has been minimized.

Copy link Quote reply

spamguy commented Sep 25, 2015

Good idea putting the logs in /Library/Logs. I had to create the directory /Library/Logs/nginx first—nginx couldn’t handle that itself.

This comment has been minimized.

Copy link Quote reply

Vetal4eg commented Oct 1, 2015

@spamguy What good in logs at /Library/Logs? Only unix way, only hardcore!

This comment has been minimized.

Copy link Quote reply

anthonybrown commented Oct 13, 2015

I can’t seem to get nginx to load anything on port :8080
brew install nginx —with-passenger

followed brew’s instructions but couldn’t get localhost to work.
I have it running on my iMac but not on my MBP, is there some difference in configuration?

This comment has been minimized.

Copy link Quote reply

wellington1993 commented Mar 30, 2016

This comment has been minimized.

Copy link Quote reply

andresnator commented May 28, 2016

This comment has been minimized.

Copy link Quote reply

iplus26 commented Jun 7, 2016

You saved my day.

Forgot to include /usr/local/etc/nginx/sites-enabled/*.conf;

This comment has been minimized.

Copy link Quote reply

raulvillca commented Aug 14, 2016

include /etc/nginx/conf.d . i must make it, cause i didn’t find it

This comment has been minimized.

Copy link Quote reply

cr2121 commented Sep 20, 2016

This comment has been minimized.

Copy link Quote reply

craigiswayne commented Dec 19, 2016

Found this «create your own signed certificate for mac» tutorial
https://certsimple.com/blog/localhost-ssl-fix

Читайте также:  Clam antivirus для linux

This comment has been minimized.

Copy link Quote reply

j0t3x commented Dec 26, 2016

This comment has been minimized.

Copy link Quote reply

sivcan commented Jan 19, 2017

Thanks a lot dude!

This comment has been minimized.

Copy link Quote reply

trainiac commented Jan 22, 2017

/usr/local/opt/nginx/sbin/nginx was /usr/local/opt/nginx/bin/nginx for me. Thanks!

This comment has been minimized.

Copy link Quote reply

Oliboy50 commented Feb 1, 2017

This comment has been minimized.

Copy link Quote reply

nyxee commented Aug 25, 2017

people always fail to inform others to edit /private/etc/hosts and add entries for the servers.

This comment has been minimized.

Copy link Quote reply

ihorvorotnov commented Feb 22, 2018

@nyxee or just let dnsmasq handle it

This comment has been minimized.

Copy link Quote reply

efthemiosprime commented Mar 25, 2018

where can i find the /private/etc/hosts?

This comment has been minimized.

Copy link Quote reply

agm1984 commented Oct 11, 2018 •

The hosts files is found at /etc/hosts in both Mac OS and Unix systems.

Typically, you can type

and it will open the file, if you have nano installed. There is a good chance you have nano installed. Try it, if not, use your favourite text editor. Make sure you open the file with elevated privileges so you can save it. It is a system file.

As mentioned above, you can also use dnsmasq which auto forwards *.dev domains in your browser to localhost.

Источник

Корректная настройка Nginx в Mac OS?

Здравствуйте, помогите пожалуйста разобраться!

Пытаюсь настроить Nginx в Mac OS.

В /usr/local/etc/nginx/servers/ создаю файл mysite_nginx.conf . В /private/etc/host добавил 127.0.0.1 mysite . Запускаю Nginx, захожу по url mysite:8888, а статика не отображается.

Команда nginx -t :

P.S. До этого использовал Nginx лишь в Ubuntu 16.04, где кастомные настройки для своего проекта создавались в папке /etc/nginx/sites-available/mysite_nginx.conf .

  • Вопрос задан более трёх лет назад
  • 8421 просмотр

Nginx слушает 80 порт, но вы продожаете ходить в 8888, т.е. мимо nginx.

А вообще, nginx точно запустился, а то сообщения об ошибках вообще-то не совместимы с нормальной работой.

Алексей Тен, вы правы я обращаясь по порту 8888 в url я проходил мимо Nginx. Написал в url-ке mysite без порта и все открылось как надо. На счет ошибок не могу сам понять в чем проблема. Проверил файлы error.log и nginx.pid по указанным адресам и они существуют. Заходил в файл /usr/local/etc/nginx/nginx.conf и там были закоментированы следующие поля:

Я их разкомментировал, и перезагрузил nginx (Команда sudo nginx -s reload).
Запустил команду nginx -t но к сожалению выдает те же ошибки. Есть идеи как исправить ситуацию?

Тестировать тоже надо используя sudo

Алексей Тен, В чем существенная разница между sudo nginx -t и nginx -t ? Понятно sudo выполняет команду от имени администратора.

Без sudo не хватает прав на открытие файлов логов.

Источник

macOS 11 Big Sur Nginx Setup: Multiple PHP Versions

December 10, 2020 by Kevin

Setup

Before starting you need xcode installed with the cli tools. Also, you will need VS Code installed with the code command in your system path.

OpenSSL

MySQL

Next, update your my.cnf

Now, secure using the password password and then restart.

Next, MySQL 8 authentication needs to be updated per user to mysql_native_password .

Postgres

Install postgresql (not the postgres app).

Now, you can check your user list.

Don’t use the default homebrew core tap for PHP. Use shivammathur/php.

Next, set PHP 7.4 as your default php CLI version.

Now, for each version update the php-fpm you will need a unique port. Change the ports of each php-fpm to match its php version number. For example, php@7.4 I use port 9074 .

Also, you will want php-fpm to run with your user account and not _www .

Optionally, before starting php-fpm, if you want to make edits to a php.ini file now is the time. For example, you might want to increase the upload_max_filesize and post_max_size to 10M .

Once you are ready, start up php-fpm for each version.

Check that you have processes running and validate your ports are correct.

Читайте также:  Activation windows exe что это

Next, and optionally, add some aliases for your CLI to use by adding the following and replacing with the version homebrew installs. This will give you quick access to a specific version when needed.

If you want to change the default php CLI you can set it using brew or, if added, the bash function phpv 7.4 .

PHP Errors

As time passes Homebrew is bound to break your PHP installations. When this happens you can reinstall the PHP version having the error. Keep in mind you may need to reconfigure that version of PHP but I’ve found your php.ini files remain the same.

Xdebug

Now, I like xdebug for development. But, this step is optional. To install xdebug for each version of php (cli and fpm) run the following.

For each version you installed update the php.ini . In our example, php@7.4.

You will need to remove the zend_extension=»xdebug.so» that is added to the top of the file by the pecl install process. The new default xdebug port is 9003 , it was port 9000 .

Add the following to the bottom of your php.ini file.

When finished adding your xdebug configuration to each version you have installed kill all the currently running php-fpm processes. This is not wise to do on a production server. On a new Mac dev setup, this is perfectly fine.

Nginx

Now, test the install is working.

Now, change the default settings.

Next, add a FastCGI gateway to php-fpm on the default server. The latest version of php installed is best. For other servers, you can set the version of PHP to the project requirement.

Next, add some basic security to your default server.

Then add the charset.

Now, you might want to allow for large file uploads.

Next, we edit the real index.html file used by nginx. So, replace the index.html with an index.php file. Then, and some php code to make sure everything is working.

To add more servers you can go to the nginx servers directory, /usr/local/etc/nginx/servers , and add them there as individual files. Here is a basic template.

To add SSL for your nginx server check out this post. I use these bash functions to make the process faster. To add a server I use the command nginxcreate my.test.x but you might want to modify the files to match your setup.

Dnsmasq

To save yourself the fuss of editing your hosts file constantly you can use dnsmasq .

Then we set up a custom hosts TLD *.x (or other hosts TLD like .test ) that point to 127.0.0.1 .

(customize the commands as needed)

Test that it is working.

MailHog

I like to have mailhog running as a development mail server. But, if you don’t want to take this step that is perfectly fine.

Now, you can access MailHog at http://localhost:8025/. However, you still need to connect MailHog to PHP and the mail mac command used by Postfix (Postfix comes with macOS Big Sur).

Add the following to the end of the file to connect MailHog to Postfix.

Send a test email and check MailHog.

Next, update each php.ini file with the following and then restart php-fpm. Note, test@localhost should be used but will be overridden by any PHP scripts that run.

Redis

Install Radis. This will install Redis Server v6.

Источник

Setting up a NGINX Server with Custom Modules on Mac OS X Using Vagrant

It has been a few years since I last played with NGINX.
This, together with the fact that my recent move to a new startup included a change of dev environment, Linux (fedora) to Mac OS X, made the task mentioned above a little more challenging.

I was working on a POC which required setting up NGINX as a reverse proxy, with Modules not included by default.
There are two ways to install NGINX Open Source:

  • From a pre-built package: includes most NGINX official modules; can be installed on Mac OS X with homebrew: $ brew install nginx
  • Compiled from the sources: the way to add particular modules including 3rd party modules or apply latest security patches.

From this point on, I’ll focus on the latter — NGINX compiled from sources with custom modules.

Читайте также:  0x800705b4 windows 10 ошибка активации как исправить

In order to compile the sources, we need to run a Linux box, preferably in a lightweight virtualization provider with command line interface.
Why not just use docker? Well, TBH our R&D consists of intensive Vagrant users, and I wanted them to have one less thing to worry about when testing my POC.

Vagrant is a tool for building and managing virtual machine environments in a single workflow.

First, we’ll need to install Vagrant

$ brew cask install virtualbox vagrant

Then, we’ll create our Linux box using Vagrant

The output of the last command should look like this:

A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

At this point, you might want to edit the Vagranfile to allow advanced features and configurations. For example, I often create port forwarding to allow access from the host to the virtual machine.

The final steps concerning Vagrant are starting the machine and ssh into it

To compile NGINX from the sources, we first need to install its dependencies: PCRE, zlib and OpenSSL.

Of course, it is also possible to download their tarballs and compile them.

Once you feel comfortable enough with Vagrant, the cool kids tend to instruct Vagrant to use a shell provisioner. Simply put, this is a shell script with all of the commands we want to be executed on provision (in our case, install the dependencies and even NGINX itself). To use it, just create the script with your desired tasks in the same exact directory as the Vagrantfile and add the highlighted line to it:

We now want to download and unpack the NGINX source files

After completing the previous steps we are finally ready to configure the build options. To do so we use the ./configure script that sets up various NGINX parameters, including paths to source and configuration files, compiler options, connection processing methods and the list of modules. The script ends up with creation of the Makefile required to compile the code and install NGINX.

There are 3 types of modules in NGINX, each configured differently:

  1. Modules built by default — can be disabled by including them in the configure script with the —without- prefix.
    Usage example: $ ./configure —without-http_empty_gif_module
  2. Modules not built by default — can be enabled manually by adding the —with- prefix to the configure script.
    Usage example: $ ./configure —with-http_auth_request_module
  3. Third party modules- NGINX functionality can be extended by compiling with your own module or a third-party module. Some third-party modules are listed here.
    Adding third party modules, as well as some of the modules not built by default, can be done statically or dynamically.
  • Statically linked modules — built into NGINX at compile time and are linked to the NGINX binary statically. Can be disabled only after NGINX recompilation. To compile specify the —add-module= option in the configure script and type in the path to the module:
  • Dynamically linked modules — compile as a shared object ( *.so file) and then dynamically load into NGINX at runtime. The modules can then be loaded or unloaded at any time with the load_module directive in the NGINX configuration file. To compile specify the —add-dynamic-module= configure option in the configure script and provide the path to the module:

To complete the installation all we need is to compile and install the build:

To verify that your NGINX is compiled with your custom module configuration, run this command and check if the output contains the expected module name:

Once the installation is finished, run NGINX

It’s worth mentioning a pretty common action — editing the NGINX configuration file, which can be found in /usr/local/nginx/conf/nginx.conf by default. Just remember to reload and restart NGINX to see your changes.

Thanks to Oded David for his help with the NGINX heavy lifting.

For (almost) daily “Today I Learned” coding tips n tricks checkout my website.

Источник

Оцените статью