日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

centos7下nginx配置

發(fā)布時(shí)間:2025/3/15 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos7下nginx配置 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、最基本的安裝配置

首先獲取Nginx的rmp包

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安裝rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

安裝Nginx yum install nginx –y

安裝完,遇到/var/run/nginx.pid(13:permission denied)錯(cuò)誤

修改配置文件內(nèi)容(/etc/nginx/nginx.conf)

events {

use epoll;

worker_connections 51200;

}

http {

server {

listen 20181;

server_name otpappsec.wanmei.com;

root /var/www/test;

index a.html;

}

server {

listen 80 ;

server_name otpappsec.wanmei.com;

root /var/www/test;

index a.html;

}

}

當(dāng)遇到上述錯(cuò)誤時(shí),reboot系統(tǒng)

之后遇到的錯(cuò)誤顯示80端口被占用,雖然配置文件沒使用80端口,很奇怪,查

了一些占用端口的進(jìn)程(lsof –i:80),kill掉,nginx啟動(dòng)就成功了,(⊙﹏⊙)b

2、使用ssl

打開一個(gè)目錄作為配置文件目錄(/usr/local/nginx/conf)

執(zhí)行命令:

2.1、使用openssl創(chuàng)建創(chuàng)建服務(wù)器私鑰,輸入相應(yīng)提示的信息

openssl genrsa -des3 -out test.key 1024

輸入密碼 111111 創(chuàng)建完成

2.2、清除以SSL啟動(dòng)Nginx時(shí)提示必須輸入密鑰 即生成一個(gè)不需要輸入密碼的key

openssl rsa -in test.key -out test_nopass.key

輸入之前的密碼 111111

2.3、創(chuàng)建證書簽名請(qǐng)求(Certificate Signing Request (CSR))

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

具體輸入信息 參考下圖

?

2.4、使用剛生成的私鑰和CSR進(jìn)行證書簽名

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

一切就緒后,修改配置文件(/etc/nginx/nginx.conf)

server {

listen 20180; 監(jiān)聽端口20180

server_name otpappsec.wanmei.com;

ssl on; 開啟443端口

ssl_certificate /usr/local/nginx/conf/test.crt; 證書位置

ssl_certificate_key /usr/local/nginx/conf/test_nopass.key; key的位置

root /var/www/test;

index a.html;

}

配置完成,restart nginx服務(wù),

之后瀏覽器訪問

3、端口轉(zhuǎn)發(fā)

配置端口如下

?events {
??? use epoll;
??? worker_connections? 51200;
}
http? {
??????? server? {
??????????????? listen????????? 20181;
??????????????? server_name???? otpappsec.wanmei.com;
??????????????? root??????????? /var/www/test;
??????????????? index?????????? a.html;
??????????????? }
??????? server? {
??????????????? listen????????? 80 ;
??????????????? server_name???? otpappsec.wanmei.com;
??????????????? root??????????? /var/www/test;
??????????????? index?????????? a.html;
??????????????? }

??????? server? {
??????????????? listen????????? 20180;
??????????????? listen????????? 443;
??????????????? server_name???? otpappsec.wanmei.com;
??????????????? ssl???????????? on;
??????????????? ssl_certificate???????? /usr/local/nginx/conf/test.crt;
??????????????? ssl_certificate_key???? /usr/local/nginx/conf/test_nopass.key;
??????????????? root??????????? /var/www/test;
??????????????? index?????????? a.html;
??????????????? }

??????? server? {
??????????????? listen????????? 80 ;
??????????????? server_name???? ssl.test.com;
??????????????? root??????????? /var/www/tet;
??????????????? index?????????? index.php index.html;
??????????????? location ~ .php$ {
??????????????????????? fastcgi_pass 127.0.0.1:9000;
??????????????????????? fastcgi_index index.php;
??????????????????????? fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
??????????????????????? include fastcgi_params;
??????????????????????? }
??????????????? }

}

4、與Apache &php&mysql 環(huán)境

可以參考如下鏈接

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7

安裝php

?yum install -y php? php-fpm

修改 /etc/php.ini文件

把cgi.fix_pathinfo=0

修改 /etc/php-fpm.d/www/conf

listen.owner = nobody listen.group = nobody

user = nginx group = nginx


修改/etc/nginx/nginx.conf文件

具體見端口轉(zhuǎn)發(fā)中 ssl.test.com中的配置


重啟nginx php-fpm


之后在瀏覽器測(cè)試

php測(cè)試文件 test.php
<?php
echo phpinfo();
?>


?

?

轉(zhuǎn)載于:https://www.cnblogs.com/playboysnow/p/6347128.html

總結(jié)

以上是生活随笔為你收集整理的centos7下nginx配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。