Replace nginx default port and configuration file location

Time:2020-1-17

Preface

Recently, in the preparation of graduation project, we have basically determined the architecture of front-end and back-end separation, so we need to use nginx.

In the past, nginx was placed on docker, so there was no worry about port change or configuration file configuration. But now it is directly placed on the server, but there is a conflict with the port of Tomcat or Apollo, so the idea of changing the port and the location of the configuration file is moved.

text

The installation of nginx on Linux

sudo apt-get install nginx

After the installation of nginx is completed, the file directory will be in /etc/nginx, which is similar to the installation of docker.

Nginx changes the configuration of the configuration file

(in fact, it’s not a replacement, it’s an increase, and it’s not so troublesome to configure.)

  • Modify nginx.conf in / etc / nginx
VIM nginx.conf -- open the file with VIM
Include / root / nginx / conf.d / *. Conf; -- put it in HTTP block, path custom switch
  • Create a new folder and restart nginx
nginx -s reload

Nginx replace default port

  • Add a statement referring to the modification of the change profile above
Include / etc / nginx / sites enabled / *; -- default, but it's better to check
  • Modify the default file in / etc / nginx / sites enabled
VIM default -- open file with VIM
Listen 8091 default? Server; -- modify the listening port
Listen [::]: 8091 default [u server; -- modify listening port
  • Restart nginx
nginx -s reload

Reenter the IP and port to see the effect, but if it is built on the server like me, remember to open the server port (I stepped on the pit a little).

This article starts with cartoon’s blog
    Please indicate the source of the Reprint: https://cartoonyu.github.io/cartoon-blog/post/nginx/ replace the default port of nginx and the location of the configuration file/