Nginx Access Configuration

Taking Nginx as an example

Install nginx

Install nginx

  • Manual installation
# Unzip the installation package.
tar zxcf openresty-$\{VERSION\}.tar.gz
  
# Enter the nginx directory
cd openresty-$\{VERSION\}
  
# Configure the installation directory, etc.
./configure --prefix=/data0 --with-http_stub_status_module --with-http_addition_module
  
# Compile and Install
make && make install
  
# Launch nginx
cd /data0/nginx/sbin
./nginx

Start the system upon turning on the power [Refer to the official documentation].](https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/)

  • Install using yum.
yum install -y nginx

2. Modify the nginx configuration file

Configuration files

  • Compiling and installing: /data0/nginx/conf/nginx.conf
  • Installation using yum: /etc/nginx/nginx.conf

Reference for website access configuration

server {
    listen       80;
    server_name  www.swikoon.com;
    
    # Configure the PC station to access the swikoon_pc directory via the domain name at www.swikoon.com.
    location / {
        ssi on;
        ssi_silent_errors on;
        ssi_types text/shtml;
        root /www/docker/ruoyi-admin/wwwroot_release/swikoon_pc;
        index index.shtml index.html index.htm;
    }
    
    # Publish Channel Resource Files
    location ~ ^/(images|img|fonts|assets|js|css)/ {
        root   /www/docker/ruoyi-admin/wwwroot_release/swikoon_pc;
        expires 1d;
    }
    
    # The resource files uploaded in the background are directed to the swikoon directory for access. If OSS is used, no configuration is required.
    location ~ ^/(resources)/ {
        root /www/docker/ruoyi-admin/wwwroot_release/swikoon;
        expires 1d;
    }
    
    # Search for dynamic template access agents
    location = /_search {
        ssi on;
        ssi_silent_errors on;
        
        proxy_buffers 32 8k;
        add_after_body "";
        proxy_cookie_path / /;
        proxy_pass http://localhost:8090;
    }

    # API Interface Request Path Proxy
    location ~ ^/(api)/ {
        proxy_buffers 32 8k;
        proxy_cookie_path / /;
        proxy_pass http://localhost:8090;
    }

    # Proxy for the Member-related News Page
    location ~ ^/(account)/ {
        ssi on;
        ssi_silent_errors on;

        proxy_buffers 32 8k;
        add_after_body "";
        proxy_cookie_path / /;
        proxy_pass http://localhost:8090;
    }
}

Reference configuration for backend services

server {
    listen       443 ssl http2;
    server_name  backend.xxx.com;
    charset utf-8;

    access_log  /var/log/nginx/backend.xxx.log  main;

    ssl_certificate "/usr/share/nginx/cert/xxx.com.pem";
    ssl_certificate_key "/usr/share/nginx/cert/xxx.com.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    location / {
        root   /data0/docker/chestnut-ui;
        try_files $uri $uri/ /index.html;
        index  index.html index.htm;
    }

    location /upload/ {
        root /data0/docker/chestnut-admin/uploadPath;
        expires 1d;
    }

    location /prod-api/ {
        proxy_set_header Host $http_host;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header REMOTE-HOST $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size 200m;
        # Proxy to backend services
        proxy_pass http://localhost:8090/;
    }
}

3. Launch nginx

  • Manual installation
# Enter the sbin directory
cd /data0/nginx/sbin
  
# Check the configuration files.
./nginx -t
  
# Restart
./nginx -s reload
  • Install using yum.
# Check the configuration files.
nginx -t
  
# Restart
./nginx -s reload

On this page