日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

windows版wsl docker desktop 安裝nginx

作者:墳場唱情歌 更新時間: 2022-07-12 編程語言

在自己的安裝過程中掛載,主要出現的問題,訪問端口出現當前無法使用此頁面或者403的情況

起初跟著網上的教程,發現訪問都會或多或少出現問題,在最后解決了。以下基礎命令都沒有寫出來,適合有經驗的小伙伴作為參考。

1、下載鏡像

docker pull nginx:1/17.8

2、安裝臨時的nginxtest容器

 docker run -d --name nginxtest -p 81:80 nginx:1.17.8

3、創建所需要的掛載文件夾,我創建在/home/xx/nginx下,xx:表示的我的電腦名稱。存放位置可以自己決定。沒有使用mkdir -p ./nginx/{www,logs,conf} 方式創建,默認會成為root用戶創建,避免其他權限,我直接手動一個個創建。cd /home/xx/

mkdir logs #日志文件夾
mkdir www  #頁面文件夾
mkdir conf #配置文件夾

4、將nginxtest容器的配置文件復制到自己的創建的文件夾中,先獲取容器ID

docker cp 13246fab6580:/etc/nginx/nginx.conf /home/xxx/nginx/conf

5、關閉nginxtest容器后,創建80端口的nginx

docker run -d -p 80:80 --name nginx -v /home/xx/nginx/www:/usr/share/nginx/html -v /home/xx/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/xx/nginx/logs:/var/log/nginx -v /home/xx/nginx/conf.d:/etc/nginx/conf.d nginx:1.17.8

6、在沒有錯的情況下訪問localhost:80 會出現我前面提到的情況,接下來是重點打開自己掛載的下的nginx.conf文件,配置


user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
	
    # 以下這部分是后續加上的,映射的80端口 ***************
	server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #這里如果不配置,出現403 
            root   /usr/share/nginx/html;  
            index  index.html index.htm;
        }
		
	}

    include /etc/nginx/conf.d/*.conf;
}

7、上面標注的出現403的現象是root對應的路徑不對,應該是指向/usr/share/nginx/html的,這個路徑,大家可以查看創建nginx容器中命令所掛載的地址就可以發現。

-v /home/nginx/html:/usr/share/nginx/html 

8、在/home/xx/www下創建index.html

<!DOCTYPE html>
<html>
<head>
    <title>網頁標題</title>
</head>
<body>
    <h1>Hello Nginx.......</h1>
</body>
</html>

9、訪問頁面

原文鏈接:https://blog.csdn.net/Qq949426/article/details/125710267

欄目分類
最近更新