In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Sometimes we want to make some strings for the contents returned by the response (such as the PHP interface). Although we can replace them with code-related methods in various languages (such as PHP's str_replace), it is more convenient to replace at the nginx level without modifying the code.
Convention: this article source code directory is uniformly placed in: / root/soft/src.
Installation
Installing this module requires the sregex runtime to be installed first:
$git clone https://github.com/agentzh/sregex$ cd sregex$ make$ make install
Then install the replace-filter-nginx-module module:
$cd / root/soft/src$ git clone https://github.com/agentzh/replace-filter-nginx-module$ wget http://nginx.org/download/nginx-1.12.2.tar.gz$ tar zxvf nginx-1.12.2.tar.gz
The module is installed statically here, and the nginx needs to be recompiled. Get the parameters for the last compilation of nginx:
Nginx-Vnginx version: nginx/1.12.2built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013TLS SNI support enabledconfigure arguments:-- user=www-- group=www-- prefix=/usr/local/nginx-- with-http_stub_status_module-- with-http_ssl_module-- with-http_gzip_static_module-- with-ipv6-- with-http_sub_module-- with-ld -opt=-ljemalloc-with-http_ssl_module-with-http_realip_module-with-http_addition_module-with-http_sub_module
Add the replace-filter-nginx-module module here:
-- add-module=/root/soft/src/replace-filter-nginx-module
Final compile command:
Cd nginx-1.12.2 $. / configure-- user=www-- group=www-- prefix=/usr/local/nginx-- with-http_stub_status_module-- with-http_gzip_static_module-- with-ipv6-- with-http_sub_module-- with-ld-opt=-ljemalloc-- with-http_ssl_module-- with-http_realip_module-- with-http_addition_module-- with-http_sub_module-- add- Module=/root/soft/src/replace-filter-nginx-module $make
Since this is an upgrade of nginx, do not make install, or you will really overwrite it. Next, replace the binaries manually:
$cp / usr/local/nginx/sbin/nginx / usr/local/nginx/sbin/nginx.bak$ cp-rfp. / objs/nginx / usr/local/nginx/sbin/
Whether the test is feasible:
$nginx-vnginx version: nginx/1.12.2
Whether the configuration is normal:
$/ usr/local/nginx/sbin/nginx-tnginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful
Configuration
The test here is to replace the img.test.com returned by the interface with media.test.com.
Modify: / usr/local/nginx/conf/vhost/test.com.conf
Location ~ [^ /]\ .php (/ | $) {# comment try_files $uri = 404; to enable pathinfo try_files $uri = 404; fastcgi_pass 127.0.0.1 uri 9000; fastcgi_index index.php; include fastcgi.conf;}
Are:
Location ~ [^ /]\ .php (/ | $) {replace_filter 'img.test.com'' media.test.com' g; replace_filter_types application/json; # comment try_files $uri = 404; to enable pathinfo try_files $uri = 404; fastcgi_pass 127.0.0.1 media.test.com' 9000; fastcgi_index index.php; include fastcgi.conf
Note that you need to add replace_filter_types.
Check whether the configuration is ok after saving:
$/ usr/local/nginx/sbin/nginx-tnginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful
Then hot restart:
# restart $service nginx restart # Hot restart $/ usr/local/nginx/sbin/nginx-s reload for the first time after the upgrade is completed
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.