nginx中nginx.conf配置
|
|
如果还想所有http请求全部转为https,在80端口增加:
|
|
其中如果报ssl的错误,应该就是因为装nginx的时候没有指定ssl配置项,要重新安装再覆盖nginx,具体如下:
1、查看之前安装nginx的配置项参数/usr/local/nginx/sbin/nginx -V
2、进入nginx源码目录(原安装包目录)重新编译的代码和模块./configure --prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
如果只是想用ssl可以这样:./configure --prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_module
3、用make不要make install,否则就覆盖安装了,make完之后在objs目录(nginx源码包的objs)下就多了个nginx,覆盖你之前的nginx就可以了。cp objs/nginx /usr/local/nginx/sbin/nginx
4、测试是否成功/usr/local/nginx/sbin/nginx -t
configure具体参数解释如下:
```
–prefix=PATH : 指定nginx的安装目录。默认 /usr/local/nginx
–conf-path=PATH : 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf
–user=name: 设置nginx工作进程的用户。安装完成后,可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。–group=name类似
–with-pcre : 设置PCRE库的源码路径,如果已通过yum方式安装,使用–with-pcre自动找到库文件。使用–with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 - 8.30)并解压,剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
–with-zlib=PATH : 指定 zlib(版本1.1.3 - 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
–with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
–with-http_stub_status_module : 用来监控 Nginx 的当前状态
–with-http_realip_module : 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意义在于能够使得后台服务器记录原始客户端的IP地址
–add-module=PATH : 添加第三方外部模块,如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译(Tengine可以在新加入module时无需重新编译)