首页 > 系统相关 >Nginx1.8.1 编译扩展https

Nginx1.8.1 编译扩展https

时间:2022-11-07 10:44:32浏览次数:67  
标签:index xh ssl local Nginx1.8 编译 https php nginx

nginx无缝编译扩展https

本贴只限用于通过编译安装的nginx,如果用的是yum源安装请卸载后参见 安装nginx部分。

一、重新编译nginx

1、查看nginx是否支持ssl

/usr/local/nginx/sbin/nginx -V

  如果显示“--with-http_ssl_module”则表示https模块已安装。

  

Nginx1.8.1 编译扩展https_配置文件

2、 如果没有则需要重新编译。找到之前安装 Nginx 时的编译目录,配置ssl模块

  之前安装目录在 /usr/local/src/nginx-1.8.1 ,如果你的在不同目录请坐适当修改。

cd /usr/local/src/nginx-1.8.1
./configure --with-http_ssl_module
make

3、编译好后通过复制到方式升级,不要执行 make install 安装

# 备份原有的 nginx
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
# 把新编译的nginx拷贝到相应的目录下
cp /usr/local/src/nginx-1.8.1/objs/nginx /usr/local/nginx/sbin/

4、最后进行平滑升级

cd /usr/local/src/nginx-1.8.1
make upgrade

5、再次查看nginx是否支持ssl

/usr/local/nginx/sbin/nginx -V

二、生成私有(不受浏览器信任)的SSL证书,如果你有公有证书请跳过此步

1、生成一个RSA密钥(xh),记住你输入的密码

openssl genrsa -des3 -out xh.key 1024

  

Nginx1.8.1 编译扩展https_配置文件_02

2、拷贝一个不需要输入密码的密钥文件

openssl rsa -in xh.key -out xh_nopass.key

 

Nginx1.8.1 编译扩展https_php_03

3、生成一个证书请求

openssl req -new -key xh.key -out xh.csr

Nginx1.8.1 编译扩展https_nginx_04

4、自己签发证书

openssl x509 -req -days 365 -in xh.csr -signkey xh.key -out xh.crt

Nginx1.8.1 编译扩展https_nginx_05

5、复制crt和key到指定目录

  注:key文件一定要复制刚才生成的 nopass 的key,复制到的目录也可以需要修改

cp xh.crt /etc/ssl/
cp xh_nopass.key /etc/ssl/

三、修改 nginx.conf 配置文件

 到此为止升级完成,如果想启用https还需要修改 nginx.conf 文件

1、打开 nginx.conf 配置文件

cd /usr/local/nginx/conf  
vim nginx.conf

2、修改配置文件如下,注意 root目录,配置文件中 php代码放在了 /home/www,请根据实际情况修改

  此配置文件配置了将80端口访问自动转到443端口。

#user  www www;
worker_processes 1;
#pid /var/run/nginx.pid;
events {
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 300;
client_max_body_size 20m;
#include /etc/nginx/conf.d/*.conf;
server
{
#listen [::]:80;
listen 80;
server_name 192.168.3.219;
return 301 https://$server_name$request_uri;
index index.html index.htm index.php;
root /home/www/public;
if (!-e $request_filename)
{
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
location /nginx_status
{
#stub_status on;
#access_log /mydata/nginx.log;
auth_basic "NginxStatus";
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires 24h;
root /home/www/public;
}
location ~ /\.
{
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
server
{
#listen [::]:443 ssl;
listen 443 ssl;
ssl on;
ssl_certificate /etc/ssl/xh.crt;
ssl_certificate_key /etc/ssl/xh_nopass.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:-LOW:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
server_name 192.168.3.219;
index index.html index.htm index.php;
root /home/www/public;
if (!-e $request_filename)
{
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
location /nginx_status
{
#stub_status on;
#access_log /home/www/nginx.log;
auth_basic "NginxStatus";
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires 24h;
root /home/www/public;
}
location ~ /\.
{
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
#fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}

3、不停止nginx服务重读配置文件

/usr/local/nginx/sbin/nginx   -s  reload

 

 

参考文献:


   ​​http://www.linuxidc.com/Linux/2013-08/88271.htm​



标签:index,xh,ssl,local,Nginx1.8,编译,https,php,nginx
From: https://blog.51cto.com/u_15862829/5828045

相关文章

  • SQLite3编译
    官方编译方式SQLite3源码提供了非常便捷的编译脚本,通过执行以下命令可以编译得到sqlite3.c、sqlite3.h、sqlite3ext.h、shell.c以及一个可执行程序sqlite3。所有的代......
  • 最新版Jenkins(jdk11)-----JAVA项目使用低版本jdk编译的解决办法
    背景开源Devops工具Jenkins宣布:从6月28日发布的Jenkins2.357和即将发布的9月LTS版本开始,Jenkins最低需要Java11。所以,你懂得,很坑,项目只是jdk1.8解决......
  • CentOS7编译安装haproxy-2.6.6
    创建用户并安装依赖包#selinux会影响haproxy启动,会有'cannotbindUNIXsocket(Permissiondenied)'的报错,请关闭它除非你知道设置selinux规则sed-i'/SELINUX/s/enf......
  • https://github.com/aimeos/aimeos-laravel 安装
    需要的安装环境Linux/Unix、WAMP/XAMP或MacOS环境PHP>=7.3(Aimeos2021.10),PHP>=8.0(Aimeos2022.04+)MySQL>=5.7.8,MariaDB>=10.2.2,PostgreSQL9.6+,SQL......
  • C#动态编译2
    思路:通过C#的编译对象CSharpCodeProvider对一段C#代码进行编译C#代码包含命名空间、类、方法。以及需要引用的命名空间可以在编译前增加DLL引用,这样动态的C#代码就可以......
  • java 编译器
    1.javac介绍2. javac文件系统3. 词法分析4.语法分析之认识树节点5.语法分析之建立抽象语法树6.符号表的组织7. 填充符号表8. 插入式注解的实现9.语......
  • clang在编译时指定目标文件所需的最低macOS版本
    调研这个的原因,是因为有个同事在macOS12.2上打包好的程序,放在macOS10.15上运行时报错:DyldErrorMessage: Symbolnotfound:__ZNKSt3__115basic_stringbufIcNS_11ch......
  • chromium的下载和编译
    chromium的下载和编译(流程详解)u012983289 于2022-08-2317:08:54chromedevtoolschromec++ 准备工作:1、         2、安装VS2019,且请......
  • onps栈移植说明(2)——编译器及os适配层移植
    2.字节对齐及基础数据类型定义    协议栈源码(码云/github)port/include/port/datatype.h中根据目标系统架构(16位or32位)及所使用的编译器定义基础数据类型及字节......
  • 3A5000 英雄无敌3编译
    下载vcmi源代码1.0.0https://github.com/vcmi/vcmi/releases/tag/1.0.0解压到vcmi1.0.0下载两个依赖库1.fuzzylitehttps://github.com/fuzzylite/fuzzylite/tree/......