首頁 運維 Nginx nginx怎麼配置

nginx怎麼配置

Nov 01, 2019 am 10:45 AM
nginx

設定nginx的方法:首先要開啟「/etc/nginx/conf.d/」資料夾;然後建立設定檔;接著在「/etc/nginx/nginx.conf」檔案中修改設定項;最後重新啟動nginx即可。

nginx怎麼配置

Nginx是一款輕量級的Web 伺服器/反向代理伺服器及電子郵件(IMAP/POP3)代理伺服器

Nginx (engine x) 也是一個高效能的HTTP和反向代理服務,也是一個IMAP/POP3/SMTP服務。 Nginx是由伊戈爾·賽索耶夫為俄羅斯訪問量第二的Rambler.ru站點(俄文:Рамблер)開發的   (建議學習:nginx教程

前後端nginx設定

1.開啟/etc/nginx/conf.d/資料夾,建立設定檔xxx.conf,內容如下:

server {
    listen 80;
    server_name **.106.2**.175;
    location / {
            root   /public/app/dist;
            index  index.php index.html index.htm;
    }
    location /sell {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   Host      $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass         http://127.0.0.1:8080;
        proxy_redirect off;
    }}
登入後複製

在/etc /nginx/nginx.conf檔案中有一行就是把剛剛設定的引進總的nginx設定中

...
    include /etc/nginx/conf.d/*.conf;...
登入後複製

3.設定完成後重新啟動nginx

nginx -t                         # 查看nginx状态
nginx -s reload            # 重新载入配置文件
nginx -s reopen           # 重启 Nginx
nginx -s stop               # 停止 Nginx
登入後複製

#設定https 

 server {
         listen 443;
         server_name xx.name.com;
         ssl on;
         index index.html index.htm;
         ssl_certificate   cert/215079423330181.cert;
         ssl_certificate_key  cert/215079423330181.key;
         ssl_session_timeout 5m;
         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
         ssl_prefer_server_ciphers on;
         location / { 
            root   /public/app/dist;
            index  index.php index.html index.htm;
         }
         location /sell {
             proxy_set_header   X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header   Host      $http_host;
             proxy_set_header X-NginX-Proxy true;
             proxy_pass         http://127.0.0.1:8080;
             proxy_redirect off;
         }
    }
登入後複製

nginx.conf 預設檔案

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    gzip on;
    gzip_static on;
    gzip_min_length 1024;
    gzip_buffers 4 16k;
    gzip_comp_level 2;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript   application/x-httpd-php application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {
         listen 443;
         server_name mp.hanxing.store;
         ssl on;
         index index.html index.htm;
         ssl_certificate   cert/cert_mp.hanxing.store.crt;
         ssl_certificate_key  cert/cert_mp.hanxing.store.key;
         ssl_session_timeout 5m;
         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
         ssl_prefer_server_ciphers on;
         location / { 
            root   /public/sell/app/dist;
            index  index.php index.html index.htm;
         }
         location /sell {
             proxy_set_header   X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header   Host      $http_host;
             proxy_set_header X-NginX-Proxy true;
             proxy_pass         http://127.0.0.1:8080;
             proxy_redirect off;
         }
         error_page 404 /404.html;
              location = /40x.html {
         }
         error_page 500 502 503 504 /50x.html;
            location = /50x.html {
         }
    }
}
登入後複製

以上是nginx怎麼配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
4 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

tomcat伺服器怎麼能讓外網訪問 tomcat伺服器怎麼能讓外網訪問 Apr 21, 2024 am 07:22 AM

要讓 Tomcat 伺服器對外網訪問,需要:修改 Tomcat 設定文件,允許外部連接。新增防火牆規則,允許存取 Tomcat 伺服器連接埠。建立 DNS 記錄,將網域名稱指向 Tomcat 伺服器公有 IP。可選:使用反向代理提升安全性和效能。可選:設定 HTTPS 以提高安全性。

thinkphp怎麼運行 thinkphp怎麼運行 Apr 09, 2024 pm 05:39 PM

ThinkPHP Framework 的本機運作步驟:下載並解壓縮 ThinkPHP Framework 到本機目錄。建立虛擬主機(可選),指向 ThinkPHP 根目錄。配置資料庫連線參數。啟動 Web 伺服器。初始化 ThinkPHP 應用程式。存取 ThinkPHP 應用程式 URL 運行。

Welcome to nginx!怎麼解決? Welcome to nginx!怎麼解決? Apr 17, 2024 am 05:12 AM

要解決"Welcome to nginx!" 錯誤,需要檢查虛擬主機配置,啟用虛擬主機,重新加載Nginx,如果無法找到虛擬主機配置文件,則創建預設頁面並重新加載Nginx,這樣錯誤訊息將消失,網站將正常顯示。

html檔案怎麼產生網址 html檔案怎麼產生網址 Apr 21, 2024 pm 12:57 PM

若要將 HTML 檔案轉換為網址,需要使用網頁伺服器,包括以下步驟:取得網頁伺服器。設定網路伺服器。上傳 HTML 文件。建立域名。路由請求。

nodejs專案怎麼部署到伺服器 nodejs專案怎麼部署到伺服器 Apr 21, 2024 am 04:40 AM

Node.js 專案的伺服器部署步驟:準備部署環境:取得伺服器存取權限、安裝 Node.js、設定 Git 儲存庫。建置應用程式:使用 npm run build 產生可部署程式碼和相依性。上傳程式碼到伺服器:透過 Git 或檔案傳輸協定。安裝依賴項:SSH 登入伺服器並使用 npm install 安裝應用程式相依性。啟動應用程式:使用 node index.js 等命令啟動應用程序,或使用 pm2 等進程管理器。設定反向代理(可選):使用 Nginx 或 Apache 等反向代理路由流量到應用程式

dockerfile中最常見的指令是什麼 dockerfile中最常見的指令是什麼 Apr 07, 2024 pm 07:21 PM

Dockerfile 中最常用的指令有:FROM:建立新映像或衍生新映像RUN:執行指令(安裝軟體、設定係統)COPY:複製本機檔案到映像ADD:類似COPY,可自動解壓縮tar 存檔或取得URL 文件CMD:指定容器啟動時的指令EXPOSE:宣告容器監聽埠(但不公開)ENV:設定環境變數VOLUME:掛載主機目錄或匿名磁碟區WORKDIR:設定容器中的工作目錄ENTRYPOINT:指定容器啟動時要執行的可執行檔(類似CMD,但不可涵蓋)

nodejs可以外網存取麼 nodejs可以外網存取麼 Apr 21, 2024 am 04:43 AM

是的,Node.js 可以外網存取。您可以使用下列方法:使用 Cloud Functions 部署函數並公開存取。使用 Express 框架建立路由並定義端點。使用 Nginx 反向代理請求到 Node.js 應用程式。使用 Docker 容器運行 Node.js 應用程式並透過連接埠映射公開。

如何使用 PHP 部署和維護網站 如何使用 PHP 部署和維護網站 May 03, 2024 am 08:54 AM

要成功部署和維護PHP網站,需要執行以下步驟:選擇Web伺服器(如Apache或Nginx)安裝PHP建立資料庫並連接PHP上傳程式碼到伺服器設定網域名稱和DNS監控網站維護步驟包括更新PHP和Web伺服器、備份網站、監控錯誤日誌和更新內容。

See all articles