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脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

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

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

要让 Tomcat 服务器对外网访问,需要:修改 Tomcat 配置文件,允许外部连接。添加防火墙规则,允许访问 Tomcat 服务器端口。创建 DNS 记录,将域名指向 Tomcat 服务器公有 IP。可选:使用反向代理提升安全性和性能。可选:设置 HTTPS 以提高安全性。

Nginx 的启动和停止命令分别为 nginx 和 nginx -s quit。启动命令直接启动服务器,而停止命令优雅地关闭服务器,允许所有当前请求处理完毕。其他可用停止信号包括 stop 和 reload。

ThinkPHP Framework 的本地运行步骤:下载并解压 ThinkPHP Framework 到本地目录。创建虚拟主机(可选),指向 ThinkPHP 根目录。配置数据库连接参数。启动 Web 服务器。初始化 ThinkPHP 应用程序。访问 ThinkPHP 应用程序 URL 运行。

要解决 "Welcome to nginx!" 错误,需要检查虚拟主机配置,启用虚拟主机,重新加载 Nginx,如果无法找到虚拟主机配置文件,则创建默认页面并重新加载 Nginx,这样错误消息将消失,网站将正常显示。

Node.js 项目的服务器部署步骤:准备部署环境:获取服务器访问权限、安装 Node.js、设置 Git 存储库。构建应用程序:使用 npm run build 生成可部署代码和依赖项。上传代码到服务器:通过 Git 或文件传输协议。安装依赖项:SSH 登录服务器并使用 npm install 安装应用程序依赖项。启动应用程序:使用 node index.js 等命令启动应用程序,或使用 pm2 等进程管理器。配置反向代理(可选):使用 Nginx 或 Apache 等反向代理路由流量到应用程

要注册 phpMyAdmin,需要先创建 MySQL 用户并授予其权限,然后下载、安装和配置 phpMyAdmin,最后登录到 phpMyAdmin 以管理数据库。

访问网站出现 nginx,原因可能是:服务器维护、服务器繁忙、浏览器缓存、DNS 问题、防火墙阻止、网站错误配置、网络连接问题或网站已关闭。尝试以下解决方案:等待维护结束、非高峰时段访问、清除浏览器缓存、刷新 DNS 缓存、禁用防火墙或防病毒软件、联系网站管理员、检查网络连接或使用搜索引擎或 Web 存档查找其他网站副本。如果问题仍然存在,请与网站管理员联系。

Docker 环境中容器通信有五种方法:共享网络、Docker Compose、网络代理、共享卷、消息队列。根据隔离性和安全性需求,选择最合适的通信方法,例如利用 Docker Compose 简化连接或使用网络代理提高隔离性。
