Server installation and domain name resolution configuration of nginx reverse proxy (Linux)

brief introduction

nginx is a lightweight web server and a reverse proxy server (domain name forwarding is the function of reverse proxy)

1.nginx can directly support rails and php programs

2. Can act as a reverse proxy server for HTTP

3. As a load balancing server

4. As a mail proxy server

5. Help front-end achieve dynamic and static separation

Features: High stability, high performance, low resource usage, rich functions and support many plug-ins, modular maintenance, support for hot deployment

Installation:

1. Installation Dependence

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2. Download the installation package

In nginx.org, you can download the desired version, $table version is a stable version, the next version is OK.
Tar-zxvf your tar package
Go into your nginx compressed directory and get ready to install

cd nginx-1.10.2

./configure

make

make install

Enter the installation directory of nginx

whereis nginx

cd /usr/local/nginx

cd /sbin

./nginx

Nginx has already been installed and started. By default, it is port 80. Enter localhost and you can see the nginx page.

2. Domain Name Resolution Configuration

Enter the installation directory of ngxin

cd /usr/local/nginx

cd conf

Create a vhost folder to store conf files for each domain name. This is to make it easier to manage the analysis of each domain name. Otherwise, they are written under nginx.conf. With the development of time, more and more content will be added, which is not easy to manage.

mkdir vhost
vim nginx.conf

insert in the margin on HTTPs server

include vhost/*.conf;

Save out

Write a configuration file admin.happymmall.com.conf

server {
listen 80; #It's listening on port 80.
#Automatically create an index, if off, then nginx will give home page 403 error, but if you know the specific path of the file, then you can still access it.
#When you visit, you will display the contents of the folder in the form of a directory, such as the server downloading the software, and he will have a variety of software directories. Of course, for some js files or something, we don't want others to see, we will set it as off.
autoindex on;
server_name admin.happymmall.com;  #Online Domain Names
access_log /usr/local/nginx/logs/access.log combined;

#By default, do not enter anything else, open the order of the home page
index index.html index.htm index.jsp index.php;
#The following two are not important because they are all configured under location
#root /devsoft/apache-tomcat-7.0.73/webapps/mmall;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
        return 404;
        }
#The main thing is location.
#Forwarding to a folder Online
location = / {
        root /product/front/mmall_admin_fe/dist/view;
        index index.html;
}
location ~ .*\.(html|htm)$ {
        root /product/front/mmall_admin_fe/dist/view;
        index index.html;
        }
#If you enter an online domain name, it will jump to tomcat
location / {
        proxy_pass http://127.0.0.1:8080/;
        add_header Access-Control-Allow-Origin '*';
        }
}

Write a second configuration file and jump to the folder example img.happymmall.com.conf

server {
    listen 80;
    autoindex off;
    server_name img.happymmall.com;
    access_log /usr/local/nginx/logs/access.log combined;
    index index.html index.htm index.jsp index.php;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\<\>].*" ){
        return 404;
    }

    location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
        deny all;
    }
    #Enter the domain name on the configuration file and jump to the folder
    location / {
        root /product/ftpfile/img/;
        add_header Access-Control-Allow-Origin *;
    }
}

After creating the edit, restart nginx to take effect

./nginx -s reload

Installation and configuration of nginx under Windows are the same as linux, but it is important to note that when modifying conf configuration file, the file path should be changed to the file path of windwos.

Keywords: Nginx PHP zlib OpenSSL

Added by jana on Sun, 30 Jun 2019 05:23:32 +0300