# Installation (from source)

Prepare for Options to pass to configure

```
./configure  --help  
```

–prefix= for specifing the directory which we want to install nginx.

modules

* some module default enable，要option out: --without-http\_
* some module default disable，要option in: --with-http\_

\--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client\_temp --http-proxy-temp-path=/var/cache/nginx/proxy\_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi\_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi\_temp --http-scgi-temp-path=/var/cache/nginx/scgi\_temp --user=nginx --group=nginx --with-http\_ssl\_module --with-http\_realip\_module --with-http\_addition\_module --with-http\_sub\_module --with-http\_dav\_module --with-http\_flv\_module --with-http\_mp4\_module --with-http\_gunzip\_module --with-http\_gzip\_static\_module --with-http\_random\_index\_module --with-http\_secure\_link\_module --with-http\_stub\_status\_module --with-http\_auth\_request\_module --with-threads --with-stream --with-stream\_ssl\_module --with-mail --with-mail\_ssl\_module --with-file-aio --with-ipv6 --with-http\_spdy\_module --with-cc-opt='-O2 -g' $ make $ make install

Perl

`--with-http_perl_module`\
`--with-http_perl_module=dynamic`enables building the [embedded Perl module](http://nginx.org/en/docs/http/ngx_http_perl_module.html). This module is not built by default.\
`--with-perl_modules_path=path`defines a directory that will keep Perl modules.`--with-perl=path`sets the name of the Perl binary.

安裝工具 path : nginx-1.16.1/\
目標安裝 path : nginx-test/

```
# create directory for target nginx
mkdir nginx-test
```

```
# untar gzip and cd to that folder
tar zxvf nginx-1.16.1.tar.gz ; cd nginx-1.16.1
```

```
./configure --prefix=/.../nginx-test \
--conf-path=/.../nginx-test/conf/nginx.conf \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_xslt_module \
--with-http_xslt_module=dynamic \

--with-http_perl_module \
--with-http_perl_module=dynamic \
--with-perl_modules_path={path} \
--with-perl={path} \

```

<div align="left"><img src="https://545953893-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4MR8LIMda2MMPAQNYl%2F-M4YRygDAFBvSsILipv4%2F-M4YScL-7syESOEJ1R_p%2Fimage.png?alt=media&#x26;token=1d5905eb-7cec-4e9e-bb7b-4539630f1704" alt=""></div>

Install the configured:

```
# make will update objs folder
make
# make install will gen files to target nginx folder
make install
```

<div align="left"><img src="https://545953893-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4MR8LIMda2MMPAQNYl%2F-M4YRygDAFBvSsILipv4%2F-M4YTBaKFrmTmScpw9ZF%2Fimage.png?alt=media&#x26;token=c895f55a-6bfb-4e78-9195-7f6129a71dfa" alt=""></div>

Start the service:

```
# change the server listen port in nginx.conf
vim nginx-test/conf/nginx.conf
 
# start the nginx server
cd nginx-test/sbin
./nginx
 
# see the nginx master process and worker process
ps -aux | grep nginx
# see the default page provided by nginx
curl http://localhost:8080/
```

Stop the service

```
# stop the nginx server
cd nginx-test/sbin
./nginx -s stop
```

To view the current version of nginx, do the following:

```
# ./nginx -v
nginx: nginx version: nginx/1.16.1
```

To debug issues, view the error.log and access.log files located under /usr/local/nginx/logs

```
# ls /usr/local/nginx/logs/
access.log
error.log
nginx.pid
```

## Main Reference

{% embed url="<http://nginx.org/en/docs/configure.html>" %}

{% embed url="<https://syslint.com/blog/tutorial/how-to-compile-and-install-nginx-from-source-on-centos-7/>" %}

{% embed url="<https://www.thegeekstuff.com/2011/07/install-nginx-from-source/>" %}

{% embed url="<https://www.cyberciti.biz/faq/how-to-install-and-use-nginx-on-centos-7-rhel-7/>" %}

## Other Reference

{% embed url="<https://shazi.info/nginx-%E7%B7%A8%E8%AD%AF%E5%8F%8A-conf-%E5%84%AA%E5%8C%96%E8%A8%AD%E5%AE%9A/>" %}

{% embed url="<https://blog.gtwang.org/linux/nginxs-auth-request-module-tutorial-examples/>" %}
