In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today Xiaobian to share with you the Nginx deployment https website and configure the address rewriting method related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you read this article after some gains, let's learn about it together.
1. Environment preparation:centos6.9 host, firewall and selinux off
Install dependency packages: yum -y install openssl-devel pcre-devel gcc
Create nginx user:
useradd -m -s /sbin/nologin nginx #Do not create home directories for nginx users, no interactive shelltar -xf nginx-1.8.0.tar.gzcd nginx-1.8.0./ configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module(--with-http_ssl_module specifies the installation of security modules, which must be installed when deploying https websites, the/usr/local/nginx directory does not need to be created in advance) make && make installcd /usr/local/nginxls /usr/local/nginx
conf #nginx configuration files logs #service logs and pid files html #site pages sbin #executable main program directory
2. Put the startup link under/usr/sbin/:
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
nginx command:
nginx #Start service nginx -s stop #Close service nginx -s reload #Reload configuration file nginx -t #Test configuration file nginx -v #View Version Info nginx -v #View compilation options
Start Service: nginx
Test whether the website can be accessed normally through ip, and the following page appears to indicate that the website configuration is successful (at this time, there is only one default http page):
3. Use openssl to generate certificates and configure https websites:
cd /usr/local/nginx/confopenssl genrsa -out my.key #Generate the private key of the rsa algorithm
openssl req -new -x509 -key my.key -out my.crt #Generate a subsignature certificate, equivalent to a public key
Modify the nginx configuration file to specify the location of the certificate:
vim /usr/local/nginx/conf/nginx.conf... ... server { listen 443 ssl; server_name www.test.com; ssl_certificate my.crt; #Specify the certificate location, default to find ssl_certificate_key my.key in the current directory; #Specify the private key location / { root /var/www/html; #Specify the root path of the web page file, separate from the http website path, so as to distinguish index.html; }}
Reload configuration file after modification: nginx -s reload
mkdir -p /var/www/htmlecho "ssl test" >/var/www/html/index.html
4. Access verification:
http access effects are as follows:
https access effects are as follows:
5. Configure http address rewriting so that clients automatically jump to https when accessing http:
vim /usr/local/nginx/conf/nginx.conf... ... server { listen 80; server_name www.test.com; rewrite ^(.*)$ https://${server_name}$1 permanent; #Redirect to https location / { root html; index index.html index.htm; }
Modify complete, reload configuration file:
nginx -s reload
6. Visit again for verification:
When accessing a web page via http, it automatically jumps to https:
If the domain name has not been resolved, please add the hosts record and write the domain name and ip correspondence to the hosts file.
The above is "Nginx deploys https website and configures the method of address rewriting" All the contents of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.