Nginx安装配置


准备文件

这里我们直接下载一个临时nginx镜像,拷贝出配置文件

docker run -p 80:80 --name nginx -d nginx:1.22.0

docker cp nginx:/etc/nginx/nginx.conf  /mydata/nginx/conf/nginx.conf

# 这个里边放置的是默认配置,也是核心配置,上边的nginx.conf引用了这个配置,高版本的nginx配置文件是分离的
docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d

# 根据需求来决定要不要拷贝这个自带的html页面
docker cp nginx:/usr/share/nginx/html /home/nginx/

# 不拷贝,也可以自己来写
echo 'hello nginx' > /mydata/nginx/html/index.html

docker rm -f nginx

一切准备好之后,开始启动并挂载相关文件:

docker run \
-p 80:80 \
--name nginx \
--restart=always \
-v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /mydata/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /mydata/nginx/log:/var/log/nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-d nginx:1.22.0
  • SSL证书启动挂载
docker run \
-p 80:80 \
-p 443:443 \
--name nginx \
--restart=always \
-v /etc/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /etc/nginx/conf/cert:/etc/nginx/cert \
-v /etc/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /etc/nginx/log:/var/log/nginx \
-v /etc/nginx/html:/usr/share/nginx/html \
-d nginx:1.22.0

cert是证书所在的路径。

服务器nginx配置SSL证书后启动报错问题解决方案

https://www.cnblogs.com/WhyShang/p/16128808.html

启动nginx时,报错:open() “/etc/nginx/mime.types“ failed

配置文件:/etc/nginx/nginx.conf中有include mime.types字段,启动时报错:open() “/etc/nginx/mime.types” failed

方法一:在配置文件中去掉include mime.types字段,重新启动nginx成功

方法二:手动生成该文件

vim /etc/nginx/mime.types

types {
# Audio
audio/midi mid midi kar;
audio/mp4 aac f4a f4b m4a;
audio/mpeg mp3;
audio/ogg oga ogg opus;
audio/x-realaudio ra;
audio/x-wav wav;
# Images
image/bmp bmp;
image/gif gif;
image/jpeg jpeg jpg;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico cur;
image/x-jng jng;
# JavaScript
application/javascript js;
application/json json;
# Manifest files
application/x-web-app-manifest+json webapp;
text/cache-manifest manifest appcache;
# Microsoft Office
application/msword doc;
application/vnd.ms-excel xls;
application/vnd.ms-powerpoint ppt;
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
# Video
video/3gpp 3gpp 3gp;
video/mp4 mp4 m4v f4v f4p;
video/mpeg mpeg mpg;
video/ogg ogv;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
# Web feeds
application/xml atom rdf rss xml;
# Web fonts
application/font-woff woff;
application/font-woff2 woff2;
application/vnd.ms-fontobject eot;
application/x-font-ttf ttc ttf;
font/opentype otf;
# Other
application/java-archive jar war ear;
application/mac-binhex40 hqx;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.wap.wmlc wmlc;
application/xhtml+xml xhtml;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/x-7z-compressed 7z;
application/x-chrome-extension crx;
application/x-opera-extension oex;
application/x-xpinstall xpi;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-bittorrent torrent;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
application/octet-stream safariextz;
text/css css;
text/html html htm shtml;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/vtt vtt;
text/x-component htc;
text/x-vcard vcf;
}

直接配置Nginx([Linux操作系统CentOS7安装Nginx详细版]_Naijia_OvO的博客-CSDN博客)

SSL证书目录位置

/usr/local/nginx/conf/cert

nginx配置文件

/usr/local/nginx/conf/nginx.conf

Linux删除指定端口

方式一:lsof命令

1、查看占用端口进程的PID

lsof -i:{端口号}

2、根据PID kill掉相关进程,直接使用kill无法删除时,再用kill -9进行删除

kill -9 {PID}

方式二:netstat命令

1、查看占用端口进程的PID

netstat -tunlp|grep {port}

实例:

[root@localhost sbin]# netstat -tunpl |grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      8197/nginx: master  
tcp6       0      0 :::80                   :::*                    LISTEN      8197/nginx: master  

实例所示的8197即是PID

2、根据PID kill掉相关进程

kill -9 {PID}


  目录