1. Install tools and libraries
# pcre is a perl library, including a perl-compatible regular expression library. The http module of nginx uses pcre to parse regular expressions
# The zlib library provides many compression and decompression methods. nginx uses zlib to gzip the contents of the http package
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2. Directory structure
Source code directory:/home/werben/pkgsrc/nginx
Installation directory:/home/werben/application/nginx
3. Download Unzip the source code
wget -c
4. Create user groups and users
groupadd www useradd -g www www
5. Compile source code
./configure --user=www --group=www --prefix=/home/werben/application/nginx --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-pcre make && make install
6. Map global commands
ln -s /home/werben/application/nginx/sbin/nginx /usr/local/bin/nginx
7. Start, stop, restart
nginx -s stop nginx -s quit ngins -s reload
8. Check the correctness of the configuration file nginx.conf
nginx -t
9. Start automatically after booting
vim /lib/systemd/system/nginx.service [unit] description=nginx after=network.target [service] type=forking execstart=nginx execreload=nginx reload execstop=nginx quit privatetmp=true [install] wantedby=multi-user.target #重新加载守护进程 systemctl daemon-reload #启动nginx服务 systemctl start nginx.service #停止nginx服务 systemctl stop nginx.service #设置开机自启动 systemctl enable nginx.service #停止开机自启动 systemctl disable nginx.service #查看服务当前状态 systemctl status nginx.service #重新启动服务 systemctl restart nginx.service #查看所有已启动的服务 systemctl list-units --type=service
10. Problems and solutions
#如果`systemctl start nginx.service`提示如下报错 job for nginx.service failed because the control process exited with error code. see "systemctl status nginx.service" and "journalctl -xe" for details. #执行 systemctl status nginx.service #如果出现如下错误 process: 35783 execstart=...nginx/sbin/nginx(code=exitedstatus=203/exec) nginx.service: control process exited, code=exited status=203 systemd[1]: nginx.service: failed with result 'exit-code'. localhost.localdomain systemd[1]: failed to start nginx. journalctl -xe #如果看到如下信息 if you believe that systemd should be allowed execute access on the> then you should report this as a bug. you can generate a local policy module to allow this access. do allow this access for now by executing: # ausearch -c '(nginx)' --raw | audit2allow -m my-nginx # semodule -x 300 -i my-nginx.pp #解决方法 setenforce 0 vim /etc/selinux/config selinux=disabled
ps: Structural description of nginx configuration files
All nginx configuration files are Located in the /etc/nginx/ directory.
The main configuration file of nginx is /etc/nginx/nginx.conf.
Creating a separate configuration file for each domain makes the server easier to maintain.
nginx server blocking files must end with .conf and are stored in the /etc/nginx/conf.d directory. You can have as many server blocks as you need.
It is a good practice to follow standard naming conventions. For example, if the domain name is mydomain.com then the configuration file should be named mydomain.com.conf
If you are using repeatable configuration segments within a domain server block, it is best to refactor these segments into fragments .
nginx log files (access.log and error.log) are located in the /var/log/nginx/ directory. It is recommended to have different access and error log files for each server module.
You can set the root of your domain document to any location you want. The most common locations for webroot include:
/home/<user_name>/<site_name> /var/www/<site_name> /var/www/html/<site_name> /opt/<site_name> /usr/share/nginx/html
The above is the detailed content of How to install nginx in a custom directory on centos8. For more information, please follow other related articles on the PHP Chinese website!

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINXUnit supports multiple programming languages and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools