Linux伺服器上安裝nginx
1. 安装依赖的软件包
安装C、C++编译器
# yum -y install gcc gcc-c++
# vi sitecustomize.py
文件内容如下:
import sys sys.setdefaultencoding('gb2312')
安装其他依赖的软件
# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
下载substitutions,主要用于nginx反向代理时内容替换
# wget -c https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/master.zip -O ngx_http_substitutions_filter_module-master.zip # unzip ngx_http_substitutions_filter_module-master.zip
2. 下载安装nginx
# wget -c http://nginx.org/download/nginx-*.*.*.tar.gz # tar -zxvf nginx-*.*.*.tar.gz # cd nginx-*.*.* # ./configure --with-http_ssl_module --add-module=../ngx_http_substitutions_filter_module-master # make # make install
3. 将nginx加入开机启动服务
创建文件/etc/init.d/nginx
# vi /etc/init.d/nginx
文件内容如下:
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 pidfile=/usr/local/nginx/logs/nginx.pid nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_C/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/nginx.lock make_dirs() { # make required directories user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` opti -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
其中常量pidfile、nginx、NGINX_CONF_FILE、lockfile请根据实际路径设置。
执行以下命令
# chmod 755 /etc/init.d/nginx # chkconfig --add nginx # chkconfig nginx on # mkdir -p /etc/nginx/conf.d # cp /usr/local/nginx/conf/nginx.conf /etc/nginx/
nginx默认配置文件为 /usr/local/ningx/conf/nginx.conf
启动nginx:
# service nginx start
4. 增加防火墙规则
(假设nginx通过80和443端口对外提供服务):
# service iptables start # //iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT # iptables -I INPUT -p tcp --dport 80 -j ACCEPT # iptables -I INPUT -p tcp --dport 443 -j ACCEPT # service iptables save # service iptables restart
# iptables --line-numbers -n -L
解决Linux路径下中文文件名乱码:
修改服务器字符集
详情参考文章 《Linux服务器乱码问题》。
安装convmv
# wget -c https://www.j3e.de/linux/convmv/convmv-1.15.tar.gz # tar -zxvf convmv-1.15.tar.gz # cd convmv-1.15 # make clean; # make install;
# ./convmv -f GBK -t UTF-8 -r --nosmart --notest userfiles/*.*
以上就介绍了Linux服务器上安装nginx,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

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

可以通過以下步驟查詢 Docker 容器名稱:列出所有容器(docker ps)。篩選容器列表(使用 grep 命令)。獲取容器名稱(位於 "NAMES" 列中)。

如何在 Windows 中配置 Nginx?安裝 Nginx 並創建虛擬主機配置。修改主配置文件並包含虛擬主機配置。啟動或重新加載 Nginx。測試配置並查看網站。選擇性啟用 SSL 並配置 SSL 證書。選擇性設置防火牆允許 80 和 443 端口流量。

在雲服務器上配置 Nginx 域名的方法:創建 A 記錄,指向雲服務器的公共 IP 地址。在 Nginx 配置文件中添加虛擬主機塊,指定偵聽端口、域名和網站根目錄。重啟 Nginx 以應用更改。訪問域名測試配置。其他注意事項:安裝 SSL 證書啟用 HTTPS、確保防火牆允許 80 端口流量、等待 DNS 解析生效。

確認 Nginx 是否啟動的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 檢查端口 80 是否開放;3. 查看系統日誌中 Nginx 啟動消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

可以查詢 Nginx 版本的方法有:使用 nginx -v 命令;查看 nginx.conf 文件中的 version 指令;打開 Nginx 錯誤頁,查看頁面的標題。

在 Docker 中創建容器: 1. 拉取鏡像: docker pull [鏡像名] 2. 創建容器: docker run [選項] [鏡像名] [命令] 3. 啟動容器: docker start [容器名]

啟動 Nginx 服務器需要按照不同操作系統採取不同的步驟:Linux/Unix 系統:安裝 Nginx 軟件包(例如使用 apt-get 或 yum)。使用 systemctl 啟動 Nginx 服務(例如 sudo systemctl start nginx)。 Windows 系統:下載並安裝 Windows 二進製文件。使用 nginx.exe 可執行文件啟動 Nginx(例如 nginx.exe -c conf\nginx.conf)。無論使用哪種操作系統,您都可以通過訪問服務器 IP

Docker 容器啟動步驟:拉取容器鏡像:運行 "docker pull [鏡像名稱]"。創建容器:使用 "docker create [選項] [鏡像名稱] [命令和參數]"。啟動容器:執行 "docker start [容器名稱或 ID]"。檢查容器狀態:通過 "docker ps" 驗證容器是否正在運行。
