Toss – How to install Nginx front-end for Apache website serving environment

888u

Last update at :2024-07-14,Edit by888u

Both Apache and Nginx have unique advantages in certain architectural environments and user needs. For example, when we use Apache to process dynamic pages, it may be easier to get started based on conventional operation proficiency, but when it comes to static processing of large website data front-end files, Nginx architecture processing has more advantages. Generally, we can see that large-scale All website environments are structured using Nginx environment.

However, for the environment that our general website or blog needs, no matter what kind of architecture is used, there is basically no big difference. This article was read by Snails abroad, and the same is compiled back to learn from everyone. In this article, I will organize and share reverse proxy for Apache using nginx: nginx will run port 80, processor caches static files (JavaScript, JPG, GIF, TXT…), Apache will run port 8080 and handle requests (PHP, ASPX...)

The specific model structure is: client-Nginx-Apache. In this article, Snail is demonstrated using centos6 64-bit environment.

First, install Apache

yum install httpd httpd-devel -y

Then we need to edit the /etc/httpd/conf/httpd.conf file and set Apache to operate on port 8080

Search for Listen 80, then change it to Listen 8080

Then, we insert the following script into the last line of the current file.

NameVirtualHost 127.0.0.1:8080# Define Server document rootDocumentRoot /var/www/html/# Define the virtual hostServerName www.laozuo.orgServerAlias ​​laozuo.orgDocumentRoot /var/www/laozuo.orgOptions FollowSymLinks -IncludesAllowOverride AllOrder allow,denyAllow from allRewriteEngine on

The premise is that we need to create a folder corresponding to the site in the /var/www/ file, and then modify the domain name in the above file to our own domain name.

Then, we restart HTTPD

service httpd restart

Second, install Nginx

Edit the /etc/yum.repos.d/nginx.repo file, and then add the following file script.

[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1

Add the above script. Then run yum install nginx -y to install and execute

After installation is complete, we need to create a site configuration file on the front end.

vi /etc/nginx/conf.d/laozuo.org.conf

Then add the script as follows

server {listen 80;server_name laozuo.org laozuo.org;access_log /var/log/nginx/laozuo.org-access_log ;error_log /var/log/nginx/laozuo.org-error_log ;

location ~* .(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|html|htm|wml)$ {root / var/www/laozuo.org;expires 365d;}

# All files are cashed for 120 minutes and up to 200 pages, this have to be removedlocation / {root /var/www/laozuo.org;proxy_redirect off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr ;proxy_set_header                           32 4k;proxy_pass http://127.0.0.1:8080/;# If the backend server send one of these error Nginx will serve from cashed filesproxy_cache_use_stale error timeout invalid_header updating;}}

Modify the corresponding domain name file to our own.

Finally, restart NGINX

service nginx restart

Third, check

lsof –i tcp:80 #for check nginxlsof –i tcp:8080 # for apache

If you see the following

We can check whether NGINX is normal by stopping APACHE service httpd stop, and then open the resolved domain name. If a 502 Bad Gateway error nginx/1.6.0 error message appears, it means that NGINX is installed normally.

To summarize, here we have installed NGINX as the front end. Generally, ordinary website building users can use an ordinary one-click package or WEB panel. There is no need to bother like this.

Recommended site search: Hong Kong server rental, how to register company domain name, high defense server, IP address query, registered domain name rental, Hong Kong cloud host, Chengdu virtual host, China agent IP, rental host, local IP query,

Toss – How to install Nginx front-end for Apache website serving environment

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码