Nginx 安装与启动
生活随笔
收集整理的這篇文章主要介紹了
Nginx 安装与启动
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
安裝 第一種安裝方式:CentOS?7下配置 yum 安裝 Nginx。 按照官方的安裝實例:https://www.nginx.com/resources/admin-guide/ 第一步,在/etc/yum.repos.d/目錄下創建一個源配置文件nginx.repo: cd /etc/yum.repos.d/vim nginx.repo
啟動
填寫如下內容:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1保存,則會產生一個/etc/yum.repos.d/nginx.repo文件。
下面直接執行如下指令即可自動安裝好Nginx:
yum install nginx -y第二種:在各平臺上直接執行對應安裝命令
# CentOS yum install nginx; # Ubuntu sudo apt-get install nginx; # Mac brew install nginx;啟動
接下來看一下nginx的安裝路徑:
[root@localhost ~]# whereis nginx nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz [root@localhost ~]#cd切換到 /usr/sbin/nginx,使用./nginx啟動nginx
如果出現:nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
多半是80端口被占用,可以通過修改nginx啟動的配置文件來修改,配置文件地址:/etc/nginx/nginx.conf
正常的話,用?ps -ef|grep nginx?應該可以看到2個進程:
[root@localhost ~]# ps -ef|grep nginx root 4804 1 0 3月26 ? 00:00:00 nginx: master process ./nginx nginx 4805 4804 0 3月26 ? 00:00:00 nginx: worker process表示啟動正常,可以使用curl http://localhost 查看nginx輸出內容,或者是通過瀏覽器來查看nginx歡迎界面
其它一些有用的啟動參數:
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]Options:-?,-h : this help-v : show version and exit-V : show version and configure options then exit-t : test configuration and exit-q : suppress non-error messages during configuration testing-s signal : send signal to a master process: stop, quit, reopen, reload-p prefix : set prefix path (default: /usr/local/Cellar/nginx/1.8.0/)-c filename : set configuration file (default: /usr/local/etc/nginx/nginx.conf)-g directives : set global directives out of configuration file特別要提一下-V(大寫),有時候不知道配置文件在哪,用這個參數就能查出來。
[root@localhost ~]# nginx -V nginx version: nginx/1.10.3 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --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=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'從輸出內容可以看出里面包含了nginx啟動的文件,啟動的配置文件,以及一些其他的參數
也可以通過nginx -t來檢查配置文件是否正確
卸載、停止服務 卸載只要把目錄刪除掉就行了,如果自己為了運維方便,做了其它啟動的腳本,同步刪除停止服務,直接kill掉nginx進程最直接。當然也可以 ./nginx -s stop
轉載于:https://www.cnblogs.com/duhuo/p/4530330.html
總結
以上是生活随笔為你收集整理的Nginx 安装与启动的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 无表头单链表增删改查操作
- 下一篇: Oracle运行set autotrac