先安裝gcc 等
yum -y install gcc gcc-c++ wget
然后裝一些庫
yum -y install gcc wget automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
進入默認的軟件目錄
cd /usr/local/src/
下載 nginx軟件
wget http://nginx.org/download/nginx-1.9.5.tar.gz
如果這個下載太慢可以在這里下載http://nginx.org/download/nginx-1.9.5.tar.gz 下載完后yum -y intall lrzsz 裝好上傳工具
然后用rz上傳到服務器
然后解壓文件.
tar zxvf nginx-1.9.5.tar.gz
進入 nginx1.9.5的源碼 如果想改版本號 可以進入源碼目錄src/core/nginx.h更改
cd nginx-1.9.5/
創建一個nginx目錄用來存放運行的臨時文件夾
mkdir -p /var/cache/nginx
開始configure
./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=nobody \ --group=nobody \ --with-pcre \ --with-http_v2_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-http_auth_request_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-ipv6 \ --with-http_v2_module \ --with-threads \ --with-stream \ --with-stream_ssl_module
接着 編譯
make
安裝
make install
啟動nginx
/usr/sbin/nginx
用ps aux來查看nginx是否啟動
ps aux|grep nginx
然后配置服務
vim /usr/lib/systemd/system/nginx.service
按i輸入以下內容
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
編輯好后保存
然后開啟開機啟動
systemctl enable nginx.service
用命令關掉nginx
pkill -9 nginx
后面可以用systemctl來操作nginx.service
systemctl start nginx.service
然后php裝好后更改配置 編輯/etc/nginx/nginx.conf
如果能正確的開啟php-fpm,就完事大吉了:
https://www.cnblogs.com/fps2tao/p/7699766.html (最下面有講php-fpm)
設置開機啟動圖形界面ntsysv
轉:http://bbs.qcloud.com/thread-10429-1-1.html