Nginx - quan1997ap/angular-app-note GitHub Wiki

Cài nginx-centos:

Cài đặt https://gist.github.com/taufiqibrahim/d7f697de6bb8b93ca348a5b94d6adbfc?fbclid=IwAR3huEexP7zXSNaW8ATJvxl4Xkyh1o8XOytJ-PZDRiWCQIyAFk8C5MAJd6g

Run : https://www.thegeekstuff.com/2011/07/install-nginx-from-source/

How to Install and Configure Nginx from Source on Linux

1. Download nginx

Download nginx from here, or use wget as shown below. The current stable version is nginx 1.0.5

cd
wget http://nginx.org/download/nginx-1.0.5.tar.gz
tar xvfz nginx-1.0.5.tar.gz
cd nginx-1.0.5

2. Install nginx

There are lot of options that you can pass to ./configure. To identify list of all the configuration options do the following.

./configure --help

image

To begin with, install nginx with the default configuration options by doing ./configure as shown below.

./configure
make
make install

image

3. Change the Default nginx Listen Port

Nginx is configured to listen by default on port 80. If you are installing this on a machine for testing purpose, that already has an apache server running, you should change the nginx listen port.

Similar to apache’s httpd.conf file, nginx has nginx.conf file located under /usr/local/nginx/conf.

In the server section of nginx.conf, change the port 80 to 8081.

# vi /usr/local/nginx/conf/nginx.conf
    server {
        listen       8081;
        server_name  localhost;

4. Start Nginx Server

  • nginx executable is located under /usr/local/nginx/sbin directory. Just call this executable to start the nginx server.
cd /usr/local/nginx/sbin
./nginx
  • Once you start this, you’ll see the nginx “master process” and “worker process” if you do ps.
# ps -ef | grep -i nginx
root     18596 13:16 nginx: master process ./nginx
nobody   18597 13:16 nginx: worker process

5. Stop Nginx Server

To stop the nginx server, do the following.

cd /usr/local/nginx/sbin
./nginx -s stop

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

# ./nginx -v
nginx: nginx version: nginx/1.0.5

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

6. Nginx logs

Mặc định nếu k config log. Thì sẽ ghi logs vào folder nginx

image

tail -n 20 access.log

7. Nginx https

Bước 1: Enable SSL Nếu cài mặc định sẽ bị lỗi

image

Bước 2: Update config. Phải run lệnh trong file cài nginx

https://programmerah.com/nginx-error-nginx-emerg-the-ssl-parameter-requires-ngx_http_ssl_module-in-project-api-nginx-conf-41485/

image

image

7. Nginx https - for IP address

https://medium.com/junior-dev/how-to-secure-a-private-ip-address-with-https-nginx-ubuntu-ef8374dbfa4e