[nginx]-external multiport map Https443 port configuration

Source: Internet
Author: User
Tags centos server nginx reverse proxy

HTTPS server configuration, domain name access by default to 443 port, if you want to simultaneously through the HTTPS domain name URL to request multiple external services, it is necessary in the Nginx configuration to rule the request and match to the corresponding internal port, which is one of the powerful features of Nginx reverse proxy, This article is mainly a record of their own configuration process, welcome to discuss the correct.

Nginx Matching Rules

To achieve the expected functionality, you need to add multiple location matching rules to the 443 port under the Nginx configuration file, as described in the following rules:

Mode meaning
Location =/uri = indicates exact match, only valid on exact match
Location ^~/uri The ^~ begins by prefixing the URL path and before the regular.
Location ~ pattern The beginning indicates a case-sensitive regular match
Location ~* pattern The beginning indicates a case-insensitive regular match
Location/uri Does not take any modifiers, it also indicates a prefix match, but after a regular match
Location/ Generic match, any request that does not match to another location will match, equivalent to the default in switch

In the case of multiple location configurations, the matching order is:

    • First exact match =
    • Next prefix matches ^~
    • followed by a regular match in the Order of the files
    • The match is then matched with a prefix without any adornments.
    • Finally, give/general match
    • When a match succeeds, the match is stopped and the request is processed according to the current matching rule

Summary: So the key to the requirements implementation is to use different matching rules to map the corresponding ports.

Find Nginx configuration file path

If the Nginx service of the CentOS server that needs to operate is not the configuration of its own deployment, it is necessary to use the instructions to find the Nginx service configuration file.

    1. To view the Nginx PID, take the commonly used port 80 as an example:

      netstat -anop | grep 0.0.0.0:80
    2. Query the currently running Nginx path with the appropriate process ID (for example: 4562):

      ll  /proc/4562/exe
    3. Once you get to the Nginx execution path, use the-t parameter to get the corresponding profile path for that process, such as:
      ```

      /usr/local/nginx/sbin/nginx-t

Nginx:the configuration file/usr/local/nginx/conf/nginx.conf syntax is OK

Nginx:configuration file/usr/local/nginx/conf/nginx.conf Test is successful

## 添加匹配规则在已经配置好的443端口下,继续添加location规则
HTTPS Server
#server {    listen 443;    server_name localhost;    ssl on;    root html;    index index.html index.htm;        *ssl证书配置规则*        location / {        proxy_pass  *服务器域名*;    }location /testA {         proxy_redirect off;       proxy_pass http://localhost:12345;    }location /testB{         proxy_redirect off;       proxy_pass http://localhost:23456;    }}
保存修改后,进行nginx的执行路径,先测试配置文件是否正确:
/usr/local/nginx/sbin/nginx-t
如果正确,重启nginx服务。
/usr/local/nginx/sbin/nginx-s Reload

' 如果一切正常,则即可在外部通过 https://Server domain name/testa ' and ' https://Server domain name/TESTB ' to complete different service requests.

[nginx]-external multiport map Https443 port configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.