# 一、下載對應當前系統版本的nginx包(package),具體版本根據本身狀況http://nginx.org/packages/ wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm # 二、創建nginx的yum倉庫 rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm # 三、下載並安裝nginx yum install nginx # 四、啓動nginx服務 systemctl start nginx # 或者 service nginx start命令也能夠
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; 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; keepalive_timeout 65; #gzip on; #若是是多站點配置,須要啓用這個配置,而後在conf.d文件夾下,建立多個配置文件便可。好比www.a.com.conf、www.b.com.conf #include /etc/nginx/conf.d/*.conf; server { listen 80; #root /usr/share/nginx/html; #index index.html index.htm; # Make site accessible from http://localhost/ server_name hwapp.netcore.cn; location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }
[root@localhost /]# whereis nginx nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz
# 檢測配置是否有問題 [root@localhost /]# /usr/sbin/nginx -t nginx: [emerg] invalid URL prefix in /etc/nginx/nginx.conf:49 nginx: configuration file /etc/nginx/nginx.conf test failed [root@localhost /]# /usr/sbin/nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
#重啓nginx服務, [root@localhost /]# sudo service nginx restart Redirecting to /bin/systemctl restart nginx.service [root@localhost /]# #或者使用reload [root@localhost /]# /usr/sbin/nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@localhost /]# sudo nginx -s reload [root@localhost /]#
setsebool -P httpd_can_network_connect 1
[hager@localhost publish]$ dotnet HelloWebApp.dll Hosting environment: Production Content root path: /opt/DotNetCorePublish/HelloWebApp/publish Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down.